package com.hivision.controller;

import com.hivision.service.PassRecordService;
import com.hivision.alimqttapi.entity.PassRecord;
import com.hivision.alimqttapi.util.AttributeValue;
import com.hivision.iot.api.AliReqClient;
import com.hivision.iot.dto.AttributeValueRequestDTO;
import com.hivision.mapper.PassRecordMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.text.SimpleDateFormat;
import java.time.Duration;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.ZoneOffset;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.stream.IntStream;

/**
 * @author 温嘉明
 */
@Slf4j
@RestController
@RequestMapping("/passRecordTest")
public class PassRecordUse {

    @Autowired
    private AliReqClient reqClient;

    @Autowired
    PassRecordService passRecordService;
    @Autowired
    PassRecordMapper passRecordMapper;
    @Autowired
    AttributeValue attributeValue;

//    List<String> accessCode = Arrays.asList("1003RB", "2001RB", "1016RB", "04TLRB", "1041RB", "04TCRB", "1085RB",
//            "1111RB", "12TCRB", "04STRB", "01SLRB", "PSJJ01", "PMC33", "02SLRB", "PSJJ02", "14TCRB", "16TCRB",
//            "DYDM01", "1191RB", "16LTRB", "26TCRB", "28TCRB", "MQHG01", "03TTRB", "31TCRB", "24LTRB", "1402RB",
//            "1398RB", "1473RB", "1521RB", "ZL01", "1541RB");

    // 2选1站点：TRB028--TRB035、RB232--RB242、XZ07--XZ08、RB279--RB293、RB283--RB297、RB291--RB305、RB521--RB550、MQ01--MQ02、SJ12#--SJ11#
    List<String> initialList = Arrays.asList("YHJ01", "XZ02", "TRB010", "XZ04", "RB028", "YHJ03",
            "YHJ10", "RB212", "YHJ12", "RB232", "SJT13", "XZ07", "RB279", "RB283", "RB291", "SJT17",
            "YHJ14", "XZ11", "YHJ15", "SJ17", "YHJ22", "SJT25", "SJ8", "RB521", "MQ01", "RB581",
            "SJ12", "SJT32", "RB764", "SJT40", "YHJ36", "RB904", "RB914", "RB931");

    List<String> accessCode = new ArrayList<>(initialList);

    List<String> waitSite = Arrays.asList("1003RB", "2001RB", "1016RB", "1018RB", "12TCRB", "04STRB", "05STRB",
            "14TCRB", "DYDM01", "DYDM02", "26TCRB", "27TCRB", "28TCRB", "29TCRB", "MQHG01", "MQHG02", "24LTRB",
            "XS01", "1152RB", "21LTRB", "45TCRB", "1424RB");
    String[] colorsTwo = {"ZB-", "ZG-", "ZJ-", "ZK-", "ZN-", "ZP-", "ZL-", "ZM-", "ZR-", "ZS-"};
//    String[] colorsOne = {"ER-", "EE-", "EM-", "LA-", "FU-"};

    // VIN码备用
    String bodyIdReserve = "AAAAA";
    // 主车型
    String[] ctypes = {"Bo", "QC", "HA", "HF", "Au"};
    // 车型改款
    String CarSeries = "A";
    // 天窗类型
    String sunRoof = "A";
    // ISS机器人(涂胶类型合并)
    String ISSCode = "A";
    // UBS机器人(涂胶类型合并)
    String UBSCode = "A";
    // 擦净机器人（喷漆类型合并）
    String CleanCode = "A";
    // B1外喷机器人（喷漆类型合并）
    String B1exCode = "A";
    // 外观检测机器人
    String checkCode = "A";
    // 自动喷蜡设备
    String WAXCode = "A";
    // 动力形式
    String engintype = "AA";
    // 座位数
    String sitCode = "A";
    // 左右舵
    String LenkerKennung = "A";
    // 车身护板
    String GuardPlate = "A";
    // 高亮膜
    String Mask = "A";
    // 48V
    String B48V = "A";
    // 清漆类型
    String clearCode = "A";
    // 生产类型
    String Factorycode = "AAA";
    // 销售地（国家/地区代码）
    String saleCode = "AAA";
    // 油箱位置
    String TankSIde = "A";
    // 套色标志
    String Twotone = "A";
    // 占位
    String Occupied = "A";
    // 物料代码备用
    String materialCodeReserve = "AA";
    // 备用属性
    String reserve = "AAAAAAA";

    // =====滑撬数据=========
    // 维护后计数
    String MaintenanceCount = "AA";
    // 生命周期计数
    String LifecycleCount = "AAAA";
    // 滑橇路径
    String SkidDestination = "AAAA";
    // 损坏的滑撬标志
    String DamagedSkid = "A";
    // 滑橇下线标志
    String identificationFeedOut = "A";
    // 备用
    String spare2 = "";



    String[] nums = {"0", "1"};
    String[] numTen = {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9"};
    String[] tcs = {"01", "02", "03"};
    String[] specials = {"01", "02", "03", "04", "05", "06", "07", "08", "09"};
    String[] stypes = {"GH", "EC", "PV", "TC", "AS", "VV"};
    String characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
    List<String> notClean = Arrays.asList("RB764", "RB753");
    List<String> twoColorSite = Arrays.asList("14TCRB", "16LTRB", "31TCRB", "32TCRB");
    protected static final String CAR_DATA = "car_data";
    private static final String PLACE_HOLDING = new String(new char[109]).replace("\0", "-");
    Boolean testFlag = true;

    Random random = new Random();
    SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

    List<String> sleepMore = Arrays.asList("04TLRB", "1041RB", "04TCRB", "1085RB");
    List<String> sleepMoreTwo = Arrays.asList("01SLRB", "PSJJ01", "PMC33", "02SLRB", "PSJJ02", "03SLRB", "PSJJ03", "PMC44", "04SLRB", "PSJJ04", "14TCRB");
    List<String> sleepMoreThree = Arrays.asList("1191RB", "1196RB", "16LTRB");
    List<String> sleepMoreFour = Arrays.asList("03TTRB", "04TTRB", "31TCRB", "32TCRB");
    List<String> sleepMoreFive = Arrays.asList("1473RB", "1521RB");


    /**
     * 车辆过点大体部分
     */
    @Scheduled(cron = "0 */1 * * * ?")
//    @Scheduled(fixedRate = 5000)
    @GetMapping("/car")
    public void passRecord() throws InterruptedException {
        //选择两路分支
        int choose = passRecordMapper.selectChoose();
        log.info("开始执行过点，时间：{}", df.format(new Date()));
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        PassRecord passRecord = new PassRecord();
        int randomColor;
        String color;

        randomColor = random.nextInt(colorsTwo.length);
        color = colorsTwo[randomColor];

//        if (choose == 1) {
//            randomColor = random.nextInt(colorsOne.length);
//            color = colorsOne[randomColor];
//        } else {
//            randomColor = random.nextInt(colorsTwo.length);
//            color = colorsTwo[randomColor];
//        }
        // 颜色
        passRecord.setColor_code(color);
//        int count = passRecordMapper.selectCount();
//        if (count >= 10) {
//            count = 1;
//            passRecord.setCount(String.format("%04d", count));
//        } else {
//            count += 1;
//            passRecord.setCount(String.format("%04d", count));
//        }

        // 车型
        int randomCtype = random.nextInt(ctypes.length);
        String ctype = ctypes[randomCtype];
        passRecord.setTypeCode(ctype);

        //dc默认为1，直通
        int randomNum = random.nextInt(nums.length);
        String dc = nums[randomNum];
        passRecord.setDc("A");
        int randomNums = random.nextInt(numTen.length);

        //站点，默认为-，先不使用随机数
//        String destination = numTen[randomNums];
        String destination = "-";
        passRecord.setDestination(destination);
//        String explable = nums[randomNum];
//        passRecord.setExplable(explable);
        passRecord.setFlag("-A");

        // 物料号
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < 14; i++) {
            int index = random.nextInt(characters.length());
            sb.append(characters.charAt(index));
        }
        passRecord.setMaterialCode(sb.toString());

        // 入涂装序列号
//        int number = passRecordMapper.selectNumber();
//        if (number < 9999) {
//            number += 1;
//            passRecord.setNumber(String.valueOf(number));
//        } else {
//            passRecord.setNumber("1");
//        }

        passRecord.setOffline("-");
        // 删掉
//        String pass = nums[randomNum];
//        //pass默认为1，直通
//        passRecord.setPass("1");
//        passRecord.setPass_point(" ");

        // 滑撬ID
        Random random = new Random();
        int number = random.nextInt(10001);
        if (number < 9999) {
            number += 1;
            passRecord.setSkidId(String.format("%04d", number));
        } else {
            passRecord.setSkidId("0001");
        }

        passRecord.setSpare1(new String(new char[4]).replace("\0", "-"));
        passRecord.setSpare2(new String(new char[4]).replace("\0", "-"));
//        passRecord.setSpare3(new String(new char[6]).replace("\0", "-"));
//        int special = random.nextInt(specials.length);
//        passRecord.setSpecial(specials[special]);

        // 滑撬类型
        int stype = this.random.nextInt(stypes.length);
        passRecord.setSkidType(stypes[stype]);

        // 车身过喷房次数
        int tc = this.random.nextInt(tcs.length);
        passRecord.setTc(tcs[tc]);

        // 来源路由-sourceRouting
        String sourceRouting = "-";
        passRecord.setSourceRouting(sourceRouting);

        // vin
        passRecord.setBodyId(generateVin());

        // VIN码备用
        passRecord.setBodyIdReserve(bodyIdReserve);
        // 车型改款
        passRecord.setCar_series(CarSeries);
        // 天窗类型
        passRecord.setSun_roof(sunRoof);
        // ISS机器人(涂胶类型合并)
        passRecord.setISS_code(ISSCode);
        //  UBS机器人(涂胶类型合并)
        passRecord.setUBS_code(UBSCode);
        //  擦净机器人（喷漆类型合并）
        passRecord.setClean_Code(CleanCode);
        //  B1外喷机器人（喷漆类型合并）
        passRecord.setB1ex_code(B1exCode);
        // 外观检测机器人
        passRecord.setCheck_code(checkCode);
        // 自动喷蜡设备
        passRecord.setWAX_code(WAXCode);
        // 动力形式
        passRecord.setEngintype(engintype);
        // 座位数
        passRecord.setSit_code(sitCode);
        // 左右舵
        passRecord.setLenkerKennung(LenkerKennung);
        // 车身护板
        passRecord.setGuardPlate(GuardPlate);
        // 高亮膜
        passRecord.setMask(Mask);
        // 48V
        passRecord.setB48V(B48V);
        // 清漆类型
        passRecord.setClear_code(clearCode);
        // 生产类型
        passRecord.setFactorycode(Factorycode);
        // 销售地（国家/地区代码）
        passRecord.setSale_code(saleCode);
        // 油箱位置
        passRecord.setTankSIde(TankSIde);
        // 套色标志
        passRecord.setTwotone(Twotone);
        // 占位
        passRecord.setOccupied(Occupied);
        // 物料代码备用
        passRecord.setMaterialCodeReserve(materialCodeReserve);
        // 备用属性
        passRecord.setReserve(reserve);

        // 维护后计数
        passRecord.setMaintenanceCount(MaintenanceCount);
        // 生命周期计数
        passRecord.setLifecycleCount(LifecycleCount);
        // 滑橇路径
        passRecord.setSkidDestination(SkidDestination);
        // 损坏的滑撬标志
        passRecord.setDamagedSkid(DamagedSkid);
        // 滑橇下线标志
        passRecord.setIdentification_feed_out(identificationFeedOut);

        //发送数据到iot
        AttributeValueRequestDTO attributeValueRequestDTO = new AttributeValueRequestDTO();
        attributeValueRequestDTO.setAssetCode("RB1117");
        attributeValueRequestDTO.setAttributeCode(CAR_DATA);
        attributeValueRequestDTO.setValue(passRecord.getFlag() + passRecord.getBodyId() + passRecord.getBodyIdReserve() + ctype + passRecord.getCar_series()
                + passRecord.getSun_roof() + color + passRecord.getISS_code() + passRecord.getUBS_code() + passRecord.getClean_Code() + passRecord.getB1ex_code()
                + passRecord.getCheck_code() + passRecord.getWAX_code() + passRecord.getEngintype() + passRecord.getSit_code() + passRecord.getLenkerKennung()
                + passRecord.getGuardPlate() + passRecord.getMask() + passRecord.getB48V() + passRecord.getClear_code() + passRecord.getFactorycode()
                + passRecord.getSale_code() + passRecord.getTankSIde() + passRecord.getTwotone() + passRecord.getOccupied() + passRecord.getMaterialCode()
                + passRecord.getMaterialCodeReserve() + passRecord.getReserve() + passRecord.getTc() + passRecord.getDc() + sourceRouting + destination + passRecord.getOffline()
                + new String(new char[4]).replace("\0", "-") + passRecord.getSkidId() + passRecord.getSkidType() + passRecord.getMaintenanceCount() + passRecord.getLifecycleCount()
                + passRecord.getSkidDestination() + passRecord.getDamagedSkid() + passRecord.getIdentification_feed_out() + new String(new char[4]).replace("\0", "-"));
        passRecord.setCar_data(attributeValueRequestDTO.getValue());
        System.out.println("*******************************************");
        System.out.println("Car_data为：" + passRecord.getCar_data());
        System.out.println("*******************************************");

        // 间休暂时不用
//        if (scheduleTime()) {
//        if(true){
        reqClient.patchAttributeValue(attributeValueRequestDTO);

//        // 记录日志
//        PassRecordLog passRecordLog = new PassRecordLog();
//        passRecordLog.setCreatTime(new Date());
//        passRecordLog.setVin(attributeValueRequestDTO.getValue().substring(2,19));
//        passRecordLog.setStationCode(attributeValueRequestDTO.getAssetCode());
//        passRecordLog.setLog("东南" + attributeValueRequestDTO.getAssetCode() + "设备cardata值为：" + attributeValueRequestDTO.getValue());
//        passRecordMapper.insertPassRecordLog(passRecordLog);

        Thread.sleep(1000);
        attributeValueRequestDTO.setValue(PLACE_HOLDING);
        reqClient.patchAttributeValue(attributeValueRequestDTO);
        passRecord.setCreateTime(new Date());
        passRecord.setSite("RB1117");
        passRecordMapper.insertPassRecord(passRecord);

//        }

        // 随机生成0或1，为1时走else分支
        Random randomNew = new Random();
        int chooseInt = randomNew.nextInt(2);

//        int i = 0;
        //循环站点
        for (int i = 0; i < accessCode.size(); i++) {
//        for (String s : accessCode) {
            String s = accessCode.get(i);
            if ("XZ04".equals(s) && 1 == chooseInt) {
                s = "XZ05";
            } else if ("YHJ12".equals(s) && 1 == chooseInt) {
                s = "YHJ13";
            } else if ("RB028".equals(s) && 1 == chooseInt) {
                s = "RB035";
            } else if ("RB232".equals(s) && 1 == chooseInt) {
                s = "RB242";
            } else if ("XZ07".equals(s) && 1 == chooseInt) {
                s = "XZ08";
            } else if ("RB279".equals(s) && 1 == chooseInt) {
                s = "RB293";
            } else if ("RB283".equals(s) && 1 == chooseInt) {
                s = "RB297";
            } else if ("RB291".equals(s) && 1 == chooseInt) {
                s = "RB305";
            } else if ("SJ17".equals(s) && 1 == chooseInt) {
                s = "RB434";
            } else if ("RB521".equals(s) && 1 == chooseInt) {
                s = "RB550";
            } else if ("MQ01".equals(s) && 1 == chooseInt) {
                s = "MQ02";
            } else if ("SJ12".equals(s) && 1 == chooseInt) {
                s = "SJ11";
            } else if ("SJT32".equals(s) && 1 == chooseInt) {
                s = "SJT34";
            } else if ("RB764".equals(s) && 1 == chooseInt) {
                s = "RB753";
            } else if ("SJT40".equals(s) && 1 == chooseInt) {
                s = "SJT41";
            }
            //集合中下标0的站点数据取 RB1117 站点数据
            if (i == 0) {
                List<PassRecord> passRecord2 = passRecordMapper.selectPassRecords("RB1117");
                if (passRecord2 != null && !passRecord2.isEmpty()) {
                    for (PassRecord record : passRecord2) {
                        if (TimeComparison(sdf.format(record.getCreateTime()), 1)) {
                            attributeValueRequestDTO.setAssetCode(s);
                            attributeValueRequestDTO.setAttributeCode(CAR_DATA);
                            s = "YHJ01";
                            passRecordMapper.updateSite(s, record.getId(), new Date());
                            attributeValueRequestDTO.setValue(record.getCar_data());
                            reqClient.patchAttributeValue(attributeValueRequestDTO);
                            Thread.sleep(1000);
                            attributeValueRequestDTO.setValue(PLACE_HOLDING);
                            reqClient.patchAttributeValue(attributeValueRequestDTO);
                        }
                    }
                }
            } else {
                //num为1，切换二选一站点，否则不切换
                String num = accessCode.get(i - 1);
                if ("XZ04".equals(num) && chooseInt == 1) {
                    num = "XZ05";
                }
                if ("RB028".equals(num) && chooseInt == 1) {
                    num = "RB035";
                }
                if ("YHJ12".equals(num) && chooseInt == 1) {
                    num = "YHJ13";
                }
                if ("RB232".equals(num) && chooseInt == 1) {
                    num = "RB242";
                }
                if ("XZ07".equals(num) && chooseInt == 1) {
                    num = "XZ08";
                }
                if ("RB279".equals(num) && chooseInt == 1) {
                    num = "RB293";
                }
                if ("RB283".equals(num) && chooseInt == 1) {
                    num = "RB297";
                }
                if ("RB291".equals(num) && chooseInt == 1) {
                    num = "RB305";
                }
                if ("SJ17".equals(num) && chooseInt == 1) {
                    num = "RB434";
                }
                if ("RB521".equals(num) && chooseInt == 1) {
                    num = "RB550";
                }
                if ("MQ01".equals(num) && chooseInt == 1) {
                    num = "MQ02";
                }
                if ("SJT32".equals(num) && chooseInt == 1) {
                    num = "SJT34";
                }
                if ("SJ12".equals(num) && chooseInt == 1) {
                    num = "SJ11";
                }
                if ("RB764".equals(num) && chooseInt == 1) {
                    num = "RB753";
                }
                if ("SJT40".equals(num) && chooseInt == 1) {
                    num = "SJT41";
                }
                List<PassRecord> passRecord2 = passRecordMapper.selectPassRecords(num);
                if (passRecord2 != null && !passRecord2.isEmpty()) {
                    for (PassRecord record : passRecord2) {
                        //各站点停留时间判断区
                        if ("YHJ01".equals(num) && !TimeComparison(sdf.format(record.getCreateTime()), 2)) {
                            continue;
                        } else if ("XZ02".equals(num) && !TimeComparison(sdf.format(record.getCreateTime()), 2)) {
                            continue;
                        } else if ("TRB010".equals(num) && !TimeComparison(sdf.format(record.getCreateTime()), 2)) {
                            continue;
                        } else if ("XZ04".equals(num) && !TimeComparison(sdf.format(record.getCreateTime()), 2)) {
                            continue;
                        } else if (("RB028".equals(num) || "RB035".equals(num)) && !TimeComparison(sdf.format(record.getCreateTime()), 2)) {
                            continue;
                        } else if ("YHJ03".equals(num) && !TimeComparison(sdf.format(record.getCreateTime()), 2)) {
                            continue;
                        } else if ("YHJ10".equals(num) && !TimeComparison(sdf.format(record.getCreateTime()), 2)) {
                            continue;
                        } else if ("RB212".equals(num) && !TimeComparison(sdf.format(record.getCreateTime()), 2)) {
                            continue;
                        } else if ("YHJ12".equals(num) && !TimeComparison(sdf.format(record.getCreateTime()), 2)) {
                            continue;
                        } else if (("RB232".equals(num) || "RB242".equals(num)) && !TimeComparison(sdf.format(record.getCreateTime()), 2)) {
                            continue;
                        } else if ("SJT13".equals(num) && !TimeComparison(sdf.format(record.getCreateTime()), 2)) {
                            continue;
                        } else if (("XZ07".equals(num) || "XZ08".equals(num)) && !TimeComparison(sdf.format(record.getCreateTime()), 2)) {
                            continue;
                        } else if (("RB279".equals(num) || "RB293".equals(num)) && !TimeComparison(sdf.format(record.getCreateTime()), 2)) {
                            continue;
                        } else if (("RB283".equals(num) || "RB297".equals(num)) && !TimeComparison(sdf.format(record.getCreateTime()), 2)) {
                            continue;
                        } else if (("RB291".equals(num) || "RB305".equals(num)) && !TimeComparison(sdf.format(record.getCreateTime()), 2)) {
                            continue;
                        } else if ("SJT17".equals(num) && !TimeComparison(sdf.format(record.getCreateTime()), 2)) {
                            continue;
                        } else if ("YHJ14".equals(num) && !TimeComparison(sdf.format(record.getCreateTime()), 2)) {
                            continue;
                        } else if ("XZ11".equals(num) && !TimeComparison(sdf.format(record.getCreateTime()), 2)) {
                            continue;
                        } else if ("YHJ15".equals(num) && !TimeComparison(sdf.format(record.getCreateTime()), 2)) {
                            continue;
                        } else if ("SJ17".equals(num) && !TimeComparison(sdf.format(record.getCreateTime()), 2)) {
                            continue;
                        } else if ("YHJ22".equals(num) && !TimeComparison(sdf.format(record.getCreateTime()), 2)) {
                            continue;
                        } else if ("SJT25".equals(num) && !TimeComparison(sdf.format(record.getCreateTime()), 2)) {
                            continue;
                        } else if ("SJ8".equals(num) && !TimeComparison(sdf.format(record.getCreateTime()), 2)) {
                            continue;
                        } else if (("RB521".equals(num) || "RB550".equals(num)) && !TimeComparison(sdf.format(record.getCreateTime()), 2)) {
                            continue;
                        } else if (("MQ01".equals(num) || "MQ02".equals(num)) && !TimeComparison(sdf.format(record.getCreateTime()), 2)) {
                            continue;
                        } else if ("RB581".equals(num) && !TimeComparison(sdf.format(record.getCreateTime()), 2)) {
                            continue;
                        } else if (("SJ12".equals(num) || "SJ11".equals(num)) && !TimeComparison(sdf.format(record.getCreateTime()), 2)) {
                            continue;
                        } else if (("RB764".equals(num) || "RB753".equals(num)) && !TimeComparison(sdf.format(record.getCreateTime()), 2)) {
                            continue;
                        } else if (("SJT40".equals(num) || "SJT41".equals(num)) && !TimeComparison(sdf.format(record.getCreateTime()), 2)) {
                            continue;
                        } else if ("YHJ36".equals(num) && !TimeComparison(sdf.format(record.getCreateTime()), 2)) {
                            continue;
                        } else if ("RB904".equals(num) && !TimeComparison(sdf.format(record.getCreateTime()), 2)) {
                            continue;
                        } else if ("RB914".equals(num) && !TimeComparison(sdf.format(record.getCreateTime()), 2)) {
                            continue;
                        } else if ("RB931".equals(num) && !TimeComparison(sdf.format(record.getCreateTime()), 2)) {
                            continue;
                        }
                        //时间不大于5分钟且属于长停留站点，不操作
                        if (waitSite.contains(record.getSite())) {
                        } else {
                            int j = 0;
//                            for (String s1 : colorsTwo) {
//                                if (s1.equals(record.getCar_data().substring(25, 28))) {
//                                    j += 1;
//                                }
//                            }
//                            for (String s1 : twoColorSite) {
//                                if (s1.equals(record.getSite())) {
//                                    j += 1;
//                                }
//                            }
                            //如果不为套色
                            if (j < 2) {
                                if (("31TCRB".equals(num) || "32TCRB".equals(num)) && !TimeComparison(sdf.format(record.getCreateTime()), 17)) {
                                    continue;
                                }

                                //停留时间大于1分钟，进行操作
                                if (TimeComparisonOneMinute(sdf.format(record.getCreateTime()))) {
                                    //16LTRB点单色直走27TCRB，避免堆积
                                    if ("16LTRB".equals(num)) {
                                        s = "27TCRB";
                                    }
                                    passRecordMapper.updateSite(s, record.getId(), new Date());
                                    attributeValueRequestDTO.setAssetCode(s);
                                    attributeValueRequestDTO.setAttributeCode(CAR_DATA);

                                    //16TCRB班内进，方向1
                                    if ("16TCRB".equals(s)) {
                                        attributeValueRequestDTO.setValue(changeDestinationFlag(record.getCar_data(), '1'));
                                        AttributeValueRequestDTO valueRequestDTO = new AttributeValueRequestDTO();
                                        valueRequestDTO.setAssetCode("16TCRB_1");
                                        valueRequestDTO.setAttributeCode(CAR_DATA);
                                        valueRequestDTO.setValue(attributeValueRequestDTO.getValue());
                                        reqClient.patchAttributeValue(valueRequestDTO);
                                        Thread.sleep(1000);
                                        valueRequestDTO.setValue(PLACE_HOLDING);
                                        reqClient.patchAttributeValue(valueRequestDTO);
                                    } else {
                                        attributeValueRequestDTO.setValue(record.getCar_data());
                                    }
//                                    //不在排班内，执行存储区录入
//                                    if (!scheduleTime()) {
////                                    if (!testFlag){
//                                        if ("16TCRB".equals(s)) {
//                                            passRecordMapper.updateSite("16TCRB-save", record.getId(), new Date());
//                                        } else if ("04TCRB".equals(s)) {
//                                            passRecordMapper.updateSite("04TCRB-save", record.getId(), new Date());
//                                        } else if ("03TTRB".equals(s)) {
//                                            passRecordMapper.updateSite("03TTRB-save", record.getId(), new Date());
//                                        } else if ("04TTRB".equals(s)) {
//                                            passRecordMapper.updateSite("04TTRB-save", record.getId(), new Date());
//                                        }
//                                    }

                                    reqClient.patchAttributeValue(attributeValueRequestDTO);
                                    Thread.sleep(1000);
                                    attributeValueRequestDTO.setValue(PLACE_HOLDING);
                                    reqClient.patchAttributeValue(attributeValueRequestDTO);
                                }
                            } else {
                                //停留时间大于1分钟，进行操作
                                if (TimeComparisonOneMinute(sdf.format(record.getCreateTime()))) {
                                    AttributeValueRequestDTO valueRequestDTO = new AttributeValueRequestDTO();
                                    valueRequestDTO.setAttributeCode(CAR_DATA);
                                    if ("14TCRB".equals(num)) {
                                        valueRequestDTO.setAssetCode("1152RB_0");
                                        valueRequestDTO.setValue(changeDestinationFlag(record.getCar_data(), '0'));
                                        reqClient.patchAttributeValue(valueRequestDTO);
                                        Thread.sleep(1000);
                                        valueRequestDTO.setValue(PLACE_HOLDING);
                                        reqClient.patchAttributeValue(valueRequestDTO);
                                        valueRequestDTO.setAssetCode("1152RB");
                                        passRecordMapper.updateSite24(valueRequestDTO.getAssetCode(), record.getId(), new Date(), "input");
                                    } else if ("16LTRB".equals(num)) {
                                        valueRequestDTO.setValue(changeDestinationFlag(record.getCar_data(), '-'));
                                        valueRequestDTO.setAssetCode("21LTRB");
                                        passRecordMapper.updateSite(valueRequestDTO.getAssetCode(), record.getId(), new Date());
                                    } else if ("31TCRB".equals(num) || "32TCRB".equals(num)) {
                                        valueRequestDTO.setAssetCode("22TCRB_0");
                                        valueRequestDTO.setValue(changeDestinationFlag(record.getCar_data(), '0'));
                                        reqClient.patchAttributeValue(valueRequestDTO);
                                        Thread.sleep(1000);
                                        valueRequestDTO.setValue(PLACE_HOLDING);
                                        reqClient.patchAttributeValue(valueRequestDTO);
                                        valueRequestDTO.setAssetCode("22TCRB");
                                        passRecordMapper.updateSite24(valueRequestDTO.getAssetCode(), record.getId(), new Date(), "input");
                                    }
                                    //16TCRB班内进，方向1
                                    if ("16TCRB".equals(s)) {
                                        valueRequestDTO.setValue(changeDestinationFlag(record.getCar_data(), '1'));
                                        AttributeValueRequestDTO valueRequestDTOa = new AttributeValueRequestDTO();
                                        valueRequestDTOa.setAssetCode("16TCRB_1");
                                        valueRequestDTOa.setAttributeCode(CAR_DATA);
                                        valueRequestDTOa.setValue(attributeValueRequestDTO.getValue());
                                        reqClient.patchAttributeValue(valueRequestDTOa);
                                        Thread.sleep(1000);
                                        valueRequestDTOa.setValue(PLACE_HOLDING);
                                        reqClient.patchAttributeValue(valueRequestDTOa);
                                    } else {
                                        valueRequestDTO.setValue(changeDestinationFlag(record.getCar_data(), '0'));
                                    }
                                    //不在排班内，执行存储区录入
                                    if (!scheduleTime()) {
//                                    if (!testFlag){
                                        if ("16TCRB".equals(s)) {
                                            passRecordMapper.updateSite("16TCRB-save", record.getId(), new Date());
                                        } else if ("04TCRB".equals(s)) {
                                            passRecordMapper.updateSite("04TCRB-save", record.getId(), new Date());
                                        } else if ("03TTRB".equals(s)) {
                                            passRecordMapper.updateSite("03TTRB-save", record.getId(), new Date());
                                        } else if ("04TTRB".equals(s)) {
                                            passRecordMapper.updateSite("04TTRB-save", record.getId(), new Date());
                                        }
                                    }
                                    reqClient.patchAttributeValue(valueRequestDTO);
                                    Thread.sleep(1000);
                                    valueRequestDTO.setValue(PLACE_HOLDING);
                                    reqClient.patchAttributeValue(valueRequestDTO);
                                }
                            }
                        }
                    }
                }
            }
        }
//        //choose值1，0切换
//        if (choose == 0) {
//            choose = 1;
//        } else {
//            choose = 0;
//        }
//        passRecordMapper.updateChoose(choose);
        log.info("过点执行结束，时间：{}", df.format(new Date()));
    }

//    /**
//     * 车辆过点大体部分
//     */
//    @Scheduled(cron = "0 */1 * * * ?")
////    @Scheduled(fixedRate = 5000)
//    @GetMapping("/car")
//    public void passRecord() throws InterruptedException {
//        //选择两路分支
//        int choose = passRecordMapper.selectChoose();
//        log.info("开始执行过点，时间：{}", df.format(new Date()));
//        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
//        PassRecord passRecord = new PassRecord();
//        int randomColor;
//        String color;
//
//        randomColor = random.nextInt(colorsTwo.length);
//        color = colorsTwo[randomColor];
//
////        if (choose == 1) {
////            randomColor = random.nextInt(colorsOne.length);
////            color = colorsOne[randomColor];
////        } else {
////            randomColor = random.nextInt(colorsTwo.length);
////            color = colorsTwo[randomColor];
////        }
//        // 颜色
//        passRecord.setColor_code(color);
////        int count = passRecordMapper.selectCount();
////        if (count >= 10) {
////            count = 1;
////            passRecord.setCount(String.format("%04d", count));
////        } else {
////            count += 1;
////            passRecord.setCount(String.format("%04d", count));
////        }
//
//        // 车型
//        int randomCtype = random.nextInt(ctypes.length);
//        String ctype = ctypes[randomCtype];
//        passRecord.setTypeCode(ctype);
//
//        //dc默认为1，直通
//        int randomNum = random.nextInt(nums.length);
//        String dc = nums[randomNum];
//        passRecord.setDc("A");
//        int randomNums = random.nextInt(numTen.length);
//
//        //站点，默认为-，先不使用随机数
////        String destination = numTen[randomNums];
//        String destination = "-";
//        passRecord.setDestination(destination);
////        String explable = nums[randomNum];
////        passRecord.setExplable(explable);
//        passRecord.setFlag("-A");
//
//        // 物料号
//        StringBuilder sb = new StringBuilder();
//        for (int i = 0; i < 14; i++) {
//            int index = random.nextInt(characters.length());
//            sb.append(characters.charAt(index));
//        }
//        passRecord.setMaterialCode(sb.toString());
//
//        // 入涂装序列号
////        int number = passRecordMapper.selectNumber();
////        if (number < 9999) {
////            number += 1;
////            passRecord.setNumber(String.valueOf(number));
////        } else {
////            passRecord.setNumber("1");
////        }
//
//        passRecord.setOffline("-");
//        // 删掉
////        String pass = nums[randomNum];
////        //pass默认为1，直通
////        passRecord.setPass("1");
////        passRecord.setPass_point(" ");
//
//        // 滑撬ID
//        Random random = new Random();
//        int number = random.nextInt(10001);
//        if (number < 9999) {
//            number += 1;
//            passRecord.setSkidId(String.format("%04d", number));
//        } else {
//            passRecord.setSkidId("0001");
//        }
//
//        passRecord.setSpare1(new String(new char[4]).replace("\0", "-"));
//        passRecord.setSpare2(new String(new char[4]).replace("\0", "-"));
////        passRecord.setSpare3(new String(new char[6]).replace("\0", "-"));
////        int special = random.nextInt(specials.length);
////        passRecord.setSpecial(specials[special]);
//
//        // 滑撬类型
//        int stype = this.random.nextInt(stypes.length);
//        passRecord.setSkidType(stypes[stype]);
//
//        // 车身过喷房次数
//        int tc = this.random.nextInt(tcs.length);
//        passRecord.setTc(tcs[tc]);
//
//        // 来源路由-sourceRouting
//        String sourceRouting = "-";
//        passRecord.setSourceRouting(sourceRouting);
//
//        // vin
//        passRecord.setBodyId(generateVin());
//
//        // VIN码备用
//        passRecord.setBodyIdReserve(bodyIdReserve);
//        // 车型改款
//        passRecord.setCar_series(CarSeries);
//        // 天窗类型
//        passRecord.setSun_roof(sunRoof);
//        // ISS机器人(涂胶类型合并)
//        passRecord.setISS_code(ISSCode);
//        //  UBS机器人(涂胶类型合并)
//        passRecord.setUBS_code(UBSCode);
//        //  擦净机器人（喷漆类型合并）
//        passRecord.setClean_Code(CleanCode);
//        //  B1外喷机器人（喷漆类型合并）
//        passRecord.setB1ex_code(B1exCode);
//        // 外观检测机器人
//        passRecord.setCheck_code(checkCode);
//        // 自动喷蜡设备
//        passRecord.setWAX_code(WAXCode);
//        // 动力形式
//        passRecord.setEngintype(engintype);
//        // 座位数
//        passRecord.setSit_code(sitCode);
//        // 左右舵
//        passRecord.setLenkerKennung(LenkerKennung);
//        // 车身护板
//        passRecord.setGuardPlate(GuardPlate);
//        // 高亮膜
//        passRecord.setMask(Mask);
//        // 48V
//        passRecord.setB48V(B48V);
//        // 清漆类型
//        passRecord.setClear_code(clearCode);
//        // 生产类型
//        passRecord.setFactorycode(Factorycode);
//        // 销售地（国家/地区代码）
//        passRecord.setSale_code(saleCode);
//        // 油箱位置
//        passRecord.setTankSIde(TankSIde);
//        // 套色标志
//        passRecord.setTwotone(Twotone);
//        // 占位
//        passRecord.setOccupied(Occupied);
//        // 物料代码备用
//        passRecord.setMaterialCodeReserve(materialCodeReserve);
//        // 备用属性
//        passRecord.setReserve(reserve);
//
//        // 维护后计数
//        passRecord.setMaintenanceCount(MaintenanceCount);
//        // 生命周期计数
//        passRecord.setLifecycleCount(LifecycleCount);
//        // 滑橇路径
//        passRecord.setSkidDestination(SkidDestination);
//        // 损坏的滑撬标志
//        passRecord.setDamagedSkid(DamagedSkid);
//        // 滑橇下线标志
//        passRecord.setIdentification_feed_out(identificationFeedOut);
//
//        //发送数据到iot
//        AttributeValueRequestDTO attributeValueRequestDTO = new AttributeValueRequestDTO();
//        attributeValueRequestDTO.setAssetCode("1001RB");
//        attributeValueRequestDTO.setAttributeCode(CAR_DATA);
//        attributeValueRequestDTO.setValue(passRecord.getFlag() + passRecord.getBodyId() + passRecord.getBodyIdReserve() + ctype + passRecord.getCar_series()
//                + passRecord.getSun_roof() + color + passRecord.getISS_code() + passRecord.getUBS_code() + passRecord.getClean_Code() + passRecord.getB1ex_code()
//                + passRecord.getCheck_code() + passRecord.getWAX_code() + passRecord.getEngintype() + passRecord.getSit_code() + passRecord.getLenkerKennung()
//                + passRecord.getGuardPlate() + passRecord.getMask() + passRecord.getB48V() + passRecord.getClear_code() + passRecord.getFactorycode()
//                + passRecord.getSale_code() + passRecord.getTankSIde() + passRecord.getTwotone() + passRecord.getOccupied() + passRecord.getMaterialCode()
//                + passRecord.getMaterialCodeReserve() + passRecord.getReserve() + passRecord.getTc() + passRecord.getDc() + sourceRouting + destination + passRecord.getOffline()
//                + new String(new char[4]).replace("\0", "-") + passRecord.getSkidId() + passRecord.getSkidType() + passRecord.getMaintenanceCount() + passRecord.getLifecycleCount()
//                + passRecord.getSkidDestination() + passRecord.getDamagedSkid() + passRecord.getIdentification_feed_out() + new String(new char[4]).replace("\0", "-"));
//        passRecord.setCar_data(attributeValueRequestDTO.getValue());
//        System.out.println("*******************************************");
//        System.out.println("Car_data为：" + passRecord.getCar_data());
//        System.out.println("*******************************************");
//
//        // 间休暂时不用
////        if (scheduleTime()) {
////        if(true){
//        reqClient.patchAttributeValue(attributeValueRequestDTO);
//        Thread.sleep(1000);
//        attributeValueRequestDTO.setValue(PLACE_HOLDING);
//        reqClient.patchAttributeValue(attributeValueRequestDTO);
//        passRecord.setCreateTime(new Date());
//        passRecord.setSite("RB1117");
//        passRecordMapper.insertPassRecord(passRecord);
////        }
//
//        // 随机生成0或1，为1时走else分支
//        Random randomNew = new Random();
//        int chooseInt = randomNew.nextInt(2);
//        int i = 0;
//        //循环站点
//        for (String s : accessCode) {
//            if ("RB028".equals(s) && 1 == chooseInt) {
//                s = "RB035";
//            } else if ("RB232".equals(s) && 1 == chooseInt) {
//                s = "RB242";
//            } else if ("XZ07".equals(s) && 1 == choose) {
//                s = "XZ08";
//            } else if ("RB279".equals(s) && 1 == choose) {
//                s = "RB293";
//            } else if ("RB283".equals(s) && 1 == choose) {
//                s = "RB297";
//            } else if ("RB291".equals(s) && 1 == choose) {
//                s = "RB305";
//            } else if ("RB521".equals(s) && 1 == choose) {
//                s = "RB550";
//            } else if ("MQ01".equals(s) && 1 == choose) {
//                s = "MQ02";
//            } else if ("SJ12".equals(s) && 1 == choose) {
//                s = "SJ11";
//            } else if ("RB764".equals(s) && 1 == choose) {
//                s = "RB753";
//            } else if ("SJT40".equals(s) && 1 == choose) {
//                s = "SJT41";
//            }
//            //集合中下标0的站点数据取 RB1117 站点数据
//            if (i == 0) {
//                List<PassRecord> passRecord2 = passRecordMapper.selectPassRecords("RB1117");
//                if (passRecord2 != null && !passRecord2.isEmpty()) {
//                    for (PassRecord record : passRecord2) {
//                        if (TimeComparison(sdf.format(record.getCreateTime()), 1)) {
//                            attributeValueRequestDTO.setAssetCode(s);
//                            attributeValueRequestDTO.setAttributeCode(CAR_DATA);
//                            s = "YHJ01";
//                            passRecordMapper.updateSite(s, record.getId(), new Date());
//                            attributeValueRequestDTO.setValue(record.getCar_data());
//                            reqClient.patchAttributeValue(attributeValueRequestDTO);
//                            Thread.sleep(1000);
//                            attributeValueRequestDTO.setValue(PLACE_HOLDING);
//                            reqClient.patchAttributeValue(attributeValueRequestDTO);
//                        }
//                    }
//                }
//            } else {
//                //num为1，切换二选一站点，否则不切换
//                String num = accessCode.get(i - 1);
//                if ("1016RB".equals(num) && choose == 1) {
//                    num = "1018RB";
//                }
//                if ("04STRB".equals(num) && choose == 1) {
//                    num = "05STRB";
//                }
//                if ("01SLRB".equals(num) && choose == 1) {
//                    num = "03SLRB";
//                }
//                if ("PMC33".equals(num) && choose == 1) {
//                    num = "PMC44";
//                }
//                if ("02SLRB".equals(num) && choose == 1) {
//                    num = "04SLRB";
//                }
//                if ("1191RB".equals(num) && choose == 1) {
//                    num = "1196RB";
//                }
//                if ("26TCRB".equals(num) && choose == 1) {
//                    num = "27TCRB";
//                }
//                if ("28TCRB".equals(num) && choose == 1) {
//                    num = "29TCRB";
//                }
//                if ("03TTRB".equals(num) && choose == 1) {
//                    num = "04TTRB";
//                }
//                if ("31TCRB".equals(num) && choose == 1) {
//                    num = "32TCRB";
//                }
//                if ("1398RB".equals(num) && choose == 1) {
//                    num = "1404RB";
//                }
//                if ("PSJJ01".equals(num) && choose == 1) {
//                    num = "PSJJ03";
//                }
//                if ("PSJJ02".equals(num) && choose == 1) {
//                    num = "PSJJ04";
//                }
//                if ("DYDM01".equals(num) && choose == 1) {
//                    num = "DYDM02";
//                }
//                if ("MQHG01".equals(num) && choose == 1) {
//                    num = "MQHG02";
//                }
//                if ("24LTRB".equals(num) && choose == 1) {
//                    num = "XS01";
//                }
//                if ("1402RB".equals(num) && choose == 1) {
//                    num = "1396RB";
//                }
//                if ("ZL01".equals(num) && choose == 1) {
//                    num = "ZL02";
//                }
//                List<PassRecord> passRecord2 = passRecordMapper.selectPassRecords(num);
//                if (passRecord2 != null && !passRecord2.isEmpty()) {
//                    for (PassRecord record : passRecord2) {
//                        //各站点停留时间判断区
//                        if ("1003RB".equals(num) && !TimeComparison(sdf.format(record.getCreateTime()), 31)) {
//                            continue;
//                        } else if ("2001RB".equals(num) && !TimeComparison(sdf.format(record.getCreateTime()), 21)) {
//                            continue;
//                        } else if (("1016RB".equals(num) || "1018RB".equals(num)) && !TimeComparison(sdf.format(record.getCreateTime()), 48)) {
//                            continue;
//                        } else if ("12TCRB".equals(num) && !TimeComparison(sdf.format(record.getCreateTime()), 5)) {
//                            continue;
//                        } else if (("04STRB".equals(num) || "05STRB".equals(num)) && !TimeComparison(sdf.format(record.getCreateTime()), 16)) {
//                            continue;
//                        } else if ("14TCRB".equals(num) && !TimeComparison(sdf.format(record.getCreateTime()), 16)) {
//                            continue;
//                        } else if (("DYDM01".equals(num) || "DYDM02".equals(num)) && !TimeComparison(sdf.format(record.getCreateTime()), 15)) {
//                            continue;
//                        } else if (("26TCRB".equals(num) || "27TCRB".equals(num)) && !TimeComparison(sdf.format(record.getCreateTime()), 12)) {
//                            continue;
//                        } else if (("28TCRB".equals(num) || "29TCRB".equals(num)) && !TimeComparison(sdf.format(record.getCreateTime()), 24)) {
//                            continue;
//                        } else if (("MQHG01".equals(num) || "MQHG02".equals(num)) && !TimeComparison(sdf.format(record.getCreateTime()), 20)) {
//                            continue;
//                        } else if (("24LTRB".equals(num) || "XS01".equals(num)) && !TimeComparison(sdf.format(record.getCreateTime()), 13)) {
//                            continue;
//                        } else if (("1398RB".equals(num) || "1404RB".equals(num)) && !TimeComparison(sdf.format(record.getCreateTime()), 15)) {
//                            continue;
//                        } else if (("ZL01".equals(num) || "ZL02".equals(num)) && !TimeComparison(sdf.format(record.getCreateTime()), 10)) {
//                            continue;
//                        } else if (sleepMore.contains(num) && !TimeComparison(sdf.format(record.getCreateTime()), 4)) {
//                            continue;
//                        } else if (sleepMoreTwo.contains(num) && !TimeComparison(sdf.format(record.getCreateTime()), 7)) {
//                            continue;
//                        } else if ("16TCRB".equals(num) && !TimeComparison(sdf.format(record.getCreateTime()), 11)) {
//                            continue;
//                        } else if (sleepMoreThree.contains(num) && !TimeComparison(sdf.format(record.getCreateTime()), 7)) {
//                            continue;
//                        } else if (sleepMoreFour.contains(num) && !TimeComparison(sdf.format(record.getCreateTime()), 5)) {
//                            continue;
//                        } else if (notClean.contains(num) && !TimeComparison(sdf.format(record.getCreateTime()), 14)) {
//                            continue;
//                        } else if (sleepMoreFive.contains(num) && !TimeComparison(sdf.format(record.getCreateTime()), 9)) {
//                            continue;
//                        }
//                        //时间不大于5分钟且属于长停留站点，不操作
//                        if (!TimeComparisonFiveMinute(sdf.format(record.getCreateTime())) && waitSite.contains(record.getSite())) {
//                        } else {
//                            int j = 0;
//                            for (String s1 : colorsTwo) {
//                                if (s1.equals(record.getCar_data().substring(25, 28))) {
//                                    j += 1;
//                                }
//                            }
//                            for (String s1 : twoColorSite) {
//                                if (s1.equals(record.getSite())) {
//                                    j += 1;
//                                }
//                            }
//                            //如果不为套色
//                            if (j < 2) {
//                                if (("31TCRB".equals(num) || "32TCRB".equals(num)) && !TimeComparison(sdf.format(record.getCreateTime()), 17)) {
//                                    continue;
//                                }
//
//                                //停留时间大于1分钟，进行操作
//                                if (TimeComparisonOneMinute(sdf.format(record.getCreateTime()))) {
//                                    //16LTRB点单色直走27TCRB，避免堆积
//                                    if ("16LTRB".equals(num)) {
//                                        s = "27TCRB";
//                                    }
//                                    passRecordMapper.updateSite(s, record.getId(), new Date());
//                                    attributeValueRequestDTO.setAssetCode(s);
//                                    attributeValueRequestDTO.setAttributeCode(CAR_DATA);
//                                    //16TCRB班内进，方向1
//                                    if ("16TCRB".equals(s)) {
//                                        attributeValueRequestDTO.setValue(changeDestinationFlag(record.getCar_data(), '1'));
//                                        AttributeValueRequestDTO valueRequestDTO = new AttributeValueRequestDTO();
//                                        valueRequestDTO.setAssetCode("16TCRB_1");
//                                        valueRequestDTO.setAttributeCode(CAR_DATA);
//                                        valueRequestDTO.setValue(attributeValueRequestDTO.getValue());
//                                        reqClient.patchAttributeValue(valueRequestDTO);
//                                        Thread.sleep(1000);
//                                        valueRequestDTO.setValue(PLACE_HOLDING);
//                                        reqClient.patchAttributeValue(valueRequestDTO);
//                                    } else {
//                                        attributeValueRequestDTO.setValue(record.getCar_data());
//                                    }
//                                    //不在排班内，执行存储区录入
//                                    if (!scheduleTime()) {
////                                    if (!testFlag){
//                                        if ("16TCRB".equals(s)) {
//                                            passRecordMapper.updateSite("16TCRB-save", record.getId(), new Date());
//                                        } else if ("04TCRB".equals(s)) {
//                                            passRecordMapper.updateSite("04TCRB-save", record.getId(), new Date());
//                                        } else if ("03TTRB".equals(s)) {
//                                            passRecordMapper.updateSite("03TTRB-save", record.getId(), new Date());
//                                        } else if ("04TTRB".equals(s)) {
//                                            passRecordMapper.updateSite("04TTRB-save", record.getId(), new Date());
//                                        }
//                                    }
//                                    reqClient.patchAttributeValue(attributeValueRequestDTO);
//                                    Thread.sleep(1000);
//                                    attributeValueRequestDTO.setValue(PLACE_HOLDING);
//                                    reqClient.patchAttributeValue(attributeValueRequestDTO);
//                                }
//                            } else {
//                                //停留时间大于1分钟，进行操作
//                                if (TimeComparisonOneMinute(sdf.format(record.getCreateTime()))) {
//                                    AttributeValueRequestDTO valueRequestDTO = new AttributeValueRequestDTO();
//                                    valueRequestDTO.setAttributeCode(CAR_DATA);
//                                    if ("14TCRB".equals(num)) {
//                                        valueRequestDTO.setAssetCode("1152RB_0");
//                                        valueRequestDTO.setValue(changeDestinationFlag(record.getCar_data(), '0'));
//                                        reqClient.patchAttributeValue(valueRequestDTO);
//                                        Thread.sleep(1000);
//                                        valueRequestDTO.setValue(PLACE_HOLDING);
//                                        reqClient.patchAttributeValue(valueRequestDTO);
//                                        valueRequestDTO.setAssetCode("1152RB");
//                                        passRecordMapper.updateSite24(valueRequestDTO.getAssetCode(), record.getId(), new Date(), "input");
//                                    } else if ("16LTRB".equals(num)) {
//                                        valueRequestDTO.setValue(changeDestinationFlag(record.getCar_data(), '-'));
//                                        valueRequestDTO.setAssetCode("21LTRB");
//                                        passRecordMapper.updateSite(valueRequestDTO.getAssetCode(), record.getId(), new Date());
//                                    } else if ("31TCRB".equals(num) || "32TCRB".equals(num)) {
//                                        valueRequestDTO.setAssetCode("22TCRB_0");
//                                        valueRequestDTO.setValue(changeDestinationFlag(record.getCar_data(), '0'));
//                                        reqClient.patchAttributeValue(valueRequestDTO);
//                                        Thread.sleep(1000);
//                                        valueRequestDTO.setValue(PLACE_HOLDING);
//                                        reqClient.patchAttributeValue(valueRequestDTO);
//                                        valueRequestDTO.setAssetCode("22TCRB");
//                                        passRecordMapper.updateSite24(valueRequestDTO.getAssetCode(), record.getId(), new Date(), "input");
//                                    }
//                                    //16TCRB班内进，方向1
//                                    if ("16TCRB".equals(s)) {
//                                        valueRequestDTO.setValue(changeDestinationFlag(record.getCar_data(), '1'));
//                                        AttributeValueRequestDTO valueRequestDTOa = new AttributeValueRequestDTO();
//                                        valueRequestDTOa.setAssetCode("16TCRB_1");
//                                        valueRequestDTOa.setAttributeCode(CAR_DATA);
//                                        valueRequestDTOa.setValue(attributeValueRequestDTO.getValue());
//                                        reqClient.patchAttributeValue(valueRequestDTOa);
//                                        Thread.sleep(1000);
//                                        valueRequestDTOa.setValue(PLACE_HOLDING);
//                                        reqClient.patchAttributeValue(valueRequestDTOa);
//                                    } else {
//                                        valueRequestDTO.setValue(changeDestinationFlag(record.getCar_data(), '0'));
//                                    }
//                                    //不在排班内，执行存储区录入
//                                    if (!scheduleTime()) {
////                                    if (!testFlag){
//                                        if ("16TCRB".equals(s)) {
//                                            passRecordMapper.updateSite("16TCRB-save", record.getId(), new Date());
//                                        } else if ("04TCRB".equals(s)) {
//                                            passRecordMapper.updateSite("04TCRB-save", record.getId(), new Date());
//                                        } else if ("03TTRB".equals(s)) {
//                                            passRecordMapper.updateSite("03TTRB-save", record.getId(), new Date());
//                                        } else if ("04TTRB".equals(s)) {
//                                            passRecordMapper.updateSite("04TTRB-save", record.getId(), new Date());
//                                        }
//                                    }
//                                    reqClient.patchAttributeValue(valueRequestDTO);
//                                    Thread.sleep(1000);
//                                    valueRequestDTO.setValue(PLACE_HOLDING);
//                                    reqClient.patchAttributeValue(valueRequestDTO);
//                                }
//                            }
//                        }
//                    }
//                }
//            }
//            i++;
//        }
//        //choose值1，0切换
//        if (choose == 0) {
//            choose = 1;
//        } else {
//            choose = 0;
//        }
//        passRecordMapper.updateChoose(choose);
//        log.info("过点执行结束，时间：{}", df.format(new Date()));
//    }


    /**
     * 返修车进入流程
     */
    @GetMapping("/XsSite")
    @Scheduled(cron = "0 */1 * * * ?")
    public void XsSite() throws InterruptedException {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        log.info("返修车进入流程执行开始，时间：{}", df.format(new Date()));
        //修饰站点逻辑块
        for (String s : notClean) {
            String num02 = attributeValue.readNum02();
            String num96 = attributeValue.readNum96();
            String num31 = attributeValue.readNum31();
            if ("RB764".equals(s) && num02 != null) {
                if ("1".equals(num02) || "2".equals(num02)) {
                    List<PassRecord> passRecordList = passRecordMapper.selectPassRecordsDesc("RB764");
                    for (PassRecord record : passRecordList) {
                        if (TimeComparison(sdf.format(record.getCreateTime()), 12)) {
                            continue;
                        }
                        List<String> repairs = new ArrayList<>();

                        List<String> sites = new ArrayList<>();
                        // 判断是大返修还是小返修，1为大返修，2为小返修
                        if ("1".equals(num31)){
                            sites.add("YHJ31_8");
                        } else {
                            sites.add("YHJ31_1");
                            sites.add("YHJ31_2");
                            sites.add("YHJ31_3");
                            sites.add("YHJ31_4");
                            sites.add("YHJ31_5");
                            sites.add("YHJ31_6");
                            sites.add("YHJ31_7");
                        }

                        for (String site : sites) {
                            String siteF = passRecordMapper.selectSite(site);
                            if (siteF == null) {
                                repairs.add(site);
                            }
                        }
                        log.info("走RB764空余反修站点{}", repairs);
                        if (!repairs.isEmpty()) {
                            Random rand = new Random();
                            s = repairs.get(rand.nextInt(repairs.size()));
                        } else {
                            s = null;
                            log.info("没有可用的点位");
                        }
                        if ("YHJ31_1".equals(s)) {
                            record.setCar_data(changeDestinationFlag(record.getCar_data(), '1'));
                            AttributeValueRequestDTO attributes = new AttributeValueRequestDTO();
                            attributes.setAssetCode("YHJ31_1");
                            attributes.setAttributeCode(CAR_DATA);
                            attributes.setValue(record.getCar_data());
                            reqClient.patchAttributeValue(attributes);
                            Thread.sleep(1000);
                            attributes.setValue(PLACE_HOLDING);
                            reqClient.patchAttributeValue(attributes);
                        } else if ("YHJ31_2".equals(s)) {
                            record.setCar_data(changeDestinationFlag(record.getCar_data(), '2'));
                            AttributeValueRequestDTO attributes = new AttributeValueRequestDTO();
                            attributes.setAssetCode("YHJ31_2");
                            attributes.setAttributeCode(CAR_DATA);
                            attributes.setValue(record.getCar_data());
                            reqClient.patchAttributeValue(attributes);
                            Thread.sleep(1000);
                            attributes.setValue(PLACE_HOLDING);
                            reqClient.patchAttributeValue(attributes);
                        } else if ("YHJ31_3".equals(s)) {
                            record.setCar_data(changeDestinationFlag(record.getCar_data(), '3'));
                            AttributeValueRequestDTO attributes = new AttributeValueRequestDTO();
                            attributes.setAssetCode("YHJ31_3");
                            attributes.setAttributeCode(CAR_DATA);
                            attributes.setValue(record.getCar_data());
                            reqClient.patchAttributeValue(attributes);
                            Thread.sleep(1000);
                            attributes.setValue(PLACE_HOLDING);
                            reqClient.patchAttributeValue(attributes);
                        } else if ("YHJ31_4".equals(s)) {
                            record.setCar_data(changeDestinationFlag(record.getCar_data(), '4'));
                            AttributeValueRequestDTO attributes = new AttributeValueRequestDTO();
                            attributes.setAssetCode("YHJ31_4");
                            attributes.setAttributeCode(CAR_DATA);
                            attributes.setValue(record.getCar_data());
                            reqClient.patchAttributeValue(attributes);
                            Thread.sleep(1000);
                            attributes.setValue(PLACE_HOLDING);
                            reqClient.patchAttributeValue(attributes);
                        } else if ("YHJ31_5".equals(s)) {
                            record.setCar_data(changeDestinationFlag(record.getCar_data(), '5'));
                            AttributeValueRequestDTO attributes = new AttributeValueRequestDTO();
                            attributes.setAssetCode("YHJ31_5");
                            attributes.setAttributeCode(CAR_DATA);
                            attributes.setValue(record.getCar_data());
                            reqClient.patchAttributeValue(attributes);
                            Thread.sleep(1000);
                            attributes.setValue(PLACE_HOLDING);
                            reqClient.patchAttributeValue(attributes);
                        } else if ("YHJ31_6".equals(s)) {
                            record.setCar_data(changeDestinationFlag(record.getCar_data(), '6'));
                            AttributeValueRequestDTO attributes = new AttributeValueRequestDTO();
                            attributes.setAssetCode("YHJ31_6");
                            attributes.setAttributeCode(CAR_DATA);
                            attributes.setValue(record.getCar_data());
                            reqClient.patchAttributeValue(attributes);
                            Thread.sleep(1000);
                            attributes.setValue(PLACE_HOLDING);
                            reqClient.patchAttributeValue(attributes);
                        } else if ("YHJ31_7".equals(s)) {
                            record.setCar_data(changeDestinationFlag(record.getCar_data(), '7'));
                            AttributeValueRequestDTO attributes = new AttributeValueRequestDTO();
                            attributes.setAssetCode("YHJ31_7");
                            attributes.setAttributeCode(CAR_DATA);
                            attributes.setValue(record.getCar_data());
                            reqClient.patchAttributeValue(attributes);
                            Thread.sleep(1000);
                            attributes.setValue(PLACE_HOLDING);
                            reqClient.patchAttributeValue(attributes);
                        } else if ("YHJ31_8".equals(s)) {
                            record.setCar_data(changeDestinationFlag(record.getCar_data(), '8'));
                            AttributeValueRequestDTO attributes = new AttributeValueRequestDTO();
                            attributes.setAssetCode("YHJ31_8");
                            attributes.setAttributeCode(CAR_DATA);
                            attributes.setValue(record.getCar_data());
                            reqClient.patchAttributeValue(attributes);
                            Thread.sleep(1000);
                            attributes.setValue(PLACE_HOLDING);
                            reqClient.patchAttributeValue(attributes);
                        }
//                        record.setCar_data(changeDestinationPass(record.getCar_data(), '0'));
                        record.setCar_data(changeDestinationDc(record.getCar_data(), '0'));
                        AttributeValueRequestDTO attributes = new AttributeValueRequestDTO();
                        if ("1".equals(num31)) {
                            attributes.setAssetCode(s);
                            s = s + "-repairOut";
                        }
                        passRecordMapper.updateCarDataAndSite(s, record.getCar_data(), record.getId(), new Date());
//                        AttributeValueRequestDTO attributes = new AttributeValueRequestDTO();
                        if ("YHJ31_1".equals(s) || "YHJ31_2".equals(s) || "YHJ31_3".equals(s) || "YHJ31_4".equals(s) || "YHJ31_5".equals(s) || "YHJ31_6".equals(s) || "YHJ31_7".equals(s) || "YHJ31_8".equals(s) ||
                                "YHJ31_1-repairOut".equals(s) || "YHJ31_2-repairOut".equals(s) || "YHJ31_3-repairOut".equals(s) || "YHJ31_4-repairOut".equals(s) || "YHJ31_5-repairOut".equals(s) ||
                                "YHJ31_6-repairOut".equals(s) || "YHJ31_7-repairOut".equals(s) || "YHJ31_8-repairOut".equals(s)) {
                            s = "YHJ31";
                            attributes.setAssetCode(s);
                        }
//                        attributes.setAssetCode(s);
                        attributes.setAttributeCode(CAR_DATA);
                        attributes.setValue(record.getCar_data());
                        reqClient.patchAttributeValue(attributes);
                        Thread.sleep(1000);
                        attributes.setValue(PLACE_HOLDING);
                        reqClient.patchAttributeValue(attributes);

                        attributes.setAssetCode("RB764_pass");
                        attributes.setAttributeCode("pass");
                        attributes.setValue("0");
                        reqClient.patchAttributeValue(attributes);

                        if (!"1".equals(num96) && !"2".equals(num96)){
                            attributes.setAssetCode("YHJ31_pass");
                            attributes.setAttributeCode("pass");
                            attributes.setValue("0");
                            reqClient.patchAttributeValue(attributes);
                        }
                    }
                }
            } else if ("RB753".equals(s) && num96 != null) {
                if ("1".equals(num96) || "2".equals(num96)) {
                    List<PassRecord> passRecordList = passRecordMapper.selectPassRecordsDesc("RB753");
                    for (PassRecord record : passRecordList) {
                        if (TimeComparison(sdf.format(record.getCreateTime()), 12)) {
                            continue;
                        }
                        List<String> repairs = new ArrayList<>();

                        List<String> sites = new ArrayList<>();
                        // 判断是大返修还是小返修，1为大返修，2为小返修
                        if ("1".equals(num31)){
                            sites.add("YHJ31_8");
                        } else {
                            sites.add("YHJ31_1");
                            sites.add("YHJ31_2");
                            sites.add("YHJ31_3");
                            sites.add("YHJ31_4");
                            sites.add("YHJ31_5");
                            sites.add("YHJ31_6");
                            sites.add("YHJ31_7");
                        }
                        for (String site : sites) {
                            String siteF = passRecordMapper.selectSite(site);
                            if (siteF == null) {
                                repairs.add(site);
                            }
                        }
                        log.info("走RB753空余反修站点{}", repairs);
                        if (!repairs.isEmpty()) {
                            Random rand = new Random();
                            s = repairs.get(rand.nextInt(repairs.size()));
                        } else {
                            s = null;
                            log.info("没有可用的点位");
                        }

                        // 向点修补里写值
                        if ("YHJ31_1".equals(s)) {
                            record.setCar_data(changeDestinationFlag(record.getCar_data(), '1'));
                            AttributeValueRequestDTO attributes = new AttributeValueRequestDTO();
                            attributes.setAssetCode("YHJ31_1");
                            attributes.setAttributeCode(CAR_DATA);
                            attributes.setValue(record.getCar_data());
                            reqClient.patchAttributeValue(attributes);
                            Thread.sleep(1000);
                            attributes.setValue(PLACE_HOLDING);
                            reqClient.patchAttributeValue(attributes);
                        } else if ("YHJ31_2".equals(s)) {
                            record.setCar_data(changeDestinationFlag(record.getCar_data(), '2'));
                            AttributeValueRequestDTO attributes = new AttributeValueRequestDTO();
                            attributes.setAssetCode("YHJ31_2");
                            attributes.setAttributeCode(CAR_DATA);
                            attributes.setValue(record.getCar_data());
                            reqClient.patchAttributeValue(attributes);
                            Thread.sleep(1000);
                            attributes.setValue(PLACE_HOLDING);
                            reqClient.patchAttributeValue(attributes);
                        } else if ("YHJ31_3".equals(s)) {
                            record.setCar_data(changeDestinationFlag(record.getCar_data(), '3'));
                            AttributeValueRequestDTO attributes = new AttributeValueRequestDTO();
                            attributes.setAssetCode("YHJ31_3");
                            attributes.setAttributeCode(CAR_DATA);
                            attributes.setValue(record.getCar_data());
                            reqClient.patchAttributeValue(attributes);
                            Thread.sleep(1000);
                            attributes.setValue(PLACE_HOLDING);
                            reqClient.patchAttributeValue(attributes);
                        } else if ("YHJ31_4".equals(s)) {
                            record.setCar_data(changeDestinationFlag(record.getCar_data(), '4'));
                            AttributeValueRequestDTO attributes = new AttributeValueRequestDTO();
                            attributes.setAssetCode("YHJ31_4");
                            attributes.setAttributeCode(CAR_DATA);
                            attributes.setValue(record.getCar_data());
                            reqClient.patchAttributeValue(attributes);
                            Thread.sleep(1000);
                            attributes.setValue(PLACE_HOLDING);
                            reqClient.patchAttributeValue(attributes);
                        } else if ("YHJ31_5".equals(s)) {
                            record.setCar_data(changeDestinationFlag(record.getCar_data(), '5'));
                            AttributeValueRequestDTO attributes = new AttributeValueRequestDTO();
                            attributes.setAssetCode("YHJ31_5");
                            attributes.setAttributeCode(CAR_DATA);
                            attributes.setValue(record.getCar_data());
                            reqClient.patchAttributeValue(attributes);
                            Thread.sleep(1000);
                            attributes.setValue(PLACE_HOLDING);
                            reqClient.patchAttributeValue(attributes);
                        } else if ("YHJ31_6".equals(s)) {
                            record.setCar_data(changeDestinationFlag(record.getCar_data(), '6'));
                            AttributeValueRequestDTO attributes = new AttributeValueRequestDTO();
                            attributes.setAssetCode("YHJ31_6");
                            attributes.setAttributeCode(CAR_DATA);
                            attributes.setValue(record.getCar_data());
                            reqClient.patchAttributeValue(attributes);
                            Thread.sleep(1000);
                            attributes.setValue(PLACE_HOLDING);
                            reqClient.patchAttributeValue(attributes);
                        } else if ("YHJ31_7".equals(s)) {
                            record.setCar_data(changeDestinationFlag(record.getCar_data(), '7'));
                            AttributeValueRequestDTO attributes = new AttributeValueRequestDTO();
                            attributes.setAssetCode("YHJ31_7");
                            attributes.setAttributeCode(CAR_DATA);
                            attributes.setValue(record.getCar_data());
                            reqClient.patchAttributeValue(attributes);
                            Thread.sleep(1000);
                            attributes.setValue(PLACE_HOLDING);
                            reqClient.patchAttributeValue(attributes);
                        } else if ("YHJ31_8".equals(s)) {
                            record.setCar_data(changeDestinationFlag(record.getCar_data(), '8'));
                            AttributeValueRequestDTO attributes = new AttributeValueRequestDTO();
                            attributes.setAssetCode("YHJ31_8");
                            attributes.setAttributeCode(CAR_DATA);
                            attributes.setValue(record.getCar_data());
                            reqClient.patchAttributeValue(attributes);
                            Thread.sleep(1000);
                            attributes.setValue(PLACE_HOLDING);
                            reqClient.patchAttributeValue(attributes);
                        }

//                        record.setCar_data(changeDestinationPass(record.getCar_data(), '0'));
                        record.setCar_data(changeDestinationDc(record.getCar_data(), '0'));
                        if ("1".equals(num31)) {
                            s = s + "-repairOut";
                        }

                        //修改数据库返修标记
                        passRecordMapper.updateCarDataAndSite(s, record.getCar_data(), record.getId(), new Date());
                        AttributeValueRequestDTO attributes = new AttributeValueRequestDTO();
                        if ("YHJ31_1".equals(s) || "YHJ31_2".equals(s) || "YHJ31_3".equals(s) || "YHJ31_4".equals(s) || "YHJ31_5".equals(s) || "YHJ31_6".equals(s) || "YHJ31_7".equals(s) || "YHJ31_8".equals(s) ||
                                "YHJ31_1-repairOut".equals(s) || "YHJ31_2-repairOut".equals(s) || "YHJ31_3-repairOut".equals(s) || "YHJ31_4-repairOut".equals(s) || "YHJ31_5-repairOut".equals(s) ||
                                "YHJ31_6-repairOut".equals(s) || "YHJ31_7-repairOut".equals(s) || "YHJ31_8-repairOut".equals(s)) {
                            s = "YHJ31";
                            attributes.setAssetCode(s);
                        }
                        attributes.setAssetCode(s);
                        attributes.setAttributeCode(CAR_DATA);
                        attributes.setValue(record.getCar_data());
                        reqClient.patchAttributeValue(attributes);
                        Thread.sleep(1000);
                        attributes.setValue(PLACE_HOLDING);
                        reqClient.patchAttributeValue(attributes);
                        attributes.setAssetCode("RB753_pass");
                        attributes.setAttributeCode("pass");
                        attributes.setValue("0");
                        reqClient.patchAttributeValue(attributes);

                        if (!"1".equals(num02) && !"2".equals(num02)){
                            attributes.setAssetCode("YHJ31_pass");
                            attributes.setAttributeCode("pass");
                            attributes.setValue("0");
                            reqClient.patchAttributeValue(attributes);
                        }
                    }
                }
            }
        }
        log.info("返修车进入流程执行结束，时间：{}", df.format(new Date()));
    }


    /**
     * 双色车流程
     */
    @GetMapping("/colorTwo")
//    @Scheduled(cron = "0 */1 * * * ?")
    public void colorTwo() throws InterruptedException {
        log.info("双色车执行开始，时间：{}", df.format(new Date()));
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        //查找进入双色点的数据1152段
        List<PassRecord> passRecords = passRecordMapper.selectPassRecordsTwoColorInput("1152RB");
        if (!passRecords.isEmpty()) {
            for (PassRecord passRecord : passRecords) {
                if (TimeComparison(sdf.format(passRecord.getCreateTime()), 10)) {
                    AttributeValueRequestDTO valueRequestDTO = new AttributeValueRequestDTO();
                    valueRequestDTO.setAttributeCode(CAR_DATA);
                    valueRequestDTO.setValue(changeDestinationFlag(passRecord.getCar_data(), '1'));
                    valueRequestDTO.setAssetCode("1152RB_1");
                    reqClient.patchAttributeValue(valueRequestDTO);
                    Thread.sleep(1000);
                    valueRequestDTO.setValue(PLACE_HOLDING);
                    reqClient.patchAttributeValue(valueRequestDTO);
                    valueRequestDTO.setAssetCode(passRecord.getSite());
                    reqClient.patchAttributeValue(valueRequestDTO);
                    Thread.sleep(1000);
                    valueRequestDTO.setValue(PLACE_HOLDING);
                    reqClient.patchAttributeValue(valueRequestDTO);
                    passRecordMapper.updateSite24(passRecord.getSite(), passRecord.getId(), new Date(), "output");
                }
            }
        }
        passRecords = passRecordMapper.selectPassRecordOutput("1152RB");
        if (!passRecords.isEmpty()) {
            for (PassRecord passRecord : passRecords) {
                if (TimeComparison(sdf.format(passRecord.getCreateTime()), 16)) {
                    AttributeValueRequestDTO valueRequestDTO = new AttributeValueRequestDTO();
                    valueRequestDTO.setAssetCode("16TCRB");
                    valueRequestDTO.setAttributeCode(CAR_DATA);
                    valueRequestDTO.setValue(changeDestinationFlag(passRecord.getCar_data(), '1'));
                    reqClient.patchAttributeValue(valueRequestDTO);
                    AttributeValueRequestDTO attributeValueRequestDTO =new AttributeValueRequestDTO();
                    attributeValueRequestDTO.setAssetCode("16TCRB_1");
                    attributeValueRequestDTO.setAttributeCode(CAR_DATA);
                    attributeValueRequestDTO.setValue(valueRequestDTO.getValue());
                    reqClient.patchAttributeValue(attributeValueRequestDTO);
                    Thread.sleep(1000);
                    valueRequestDTO.setValue(PLACE_HOLDING);
                    reqClient.patchAttributeValue(valueRequestDTO);
                    attributeValueRequestDTO.setValue(PLACE_HOLDING);
                    reqClient.patchAttributeValue(attributeValueRequestDTO);
                    passRecordMapper.updateSite("16TCRB", passRecord.getId(), new Date());
                }
            }
        }
        //21LTRB段
        List<PassRecord> passRecordList = passRecordMapper.selectPassRecords("21LTRB");
        if (!passRecordList.isEmpty()) {
            for (PassRecord passRecord : passRecordList) {
                if (TimeComparison(sdf.format(passRecord.getCreateTime()), 8)) {
                    AttributeValueRequestDTO valueRequestDTO = new AttributeValueRequestDTO();
                    valueRequestDTO.setAssetCode("1231RB");
                    valueRequestDTO.setAttributeCode(CAR_DATA);
                    valueRequestDTO.setValue(passRecord.getCar_data());
                    reqClient.patchAttributeValue(valueRequestDTO);
                    Thread.sleep(1000);
                    valueRequestDTO.setValue(PLACE_HOLDING);
                    reqClient.patchAttributeValue(valueRequestDTO);
                    passRecordMapper.updateSite("1231RB", passRecord.getId(), new Date());
                }
            }
        }

        passRecordList = passRecordMapper.selectPassRecords("1231RB");
        if (!passRecordList.isEmpty()) {
            for (PassRecord passRecord : passRecordList) {
                if (TimeComparison(sdf.format(passRecord.getCreateTime()), 16)) {
                    AttributeValueRequestDTO valueRequestDTO = new AttributeValueRequestDTO();
                    valueRequestDTO.setAssetCode("45TCRB");
                    valueRequestDTO.setAttributeCode(CAR_DATA);
                    valueRequestDTO.setValue(passRecord.getCar_data());
                    reqClient.patchAttributeValue(valueRequestDTO);
                    Thread.sleep(1000);
                    valueRequestDTO.setValue(PLACE_HOLDING);
                    reqClient.patchAttributeValue(valueRequestDTO);
                    passRecordMapper.updateSite("45TCRB", passRecord.getId(), new Date());
                }
            }
        }
        passRecordList = passRecordMapper.selectPassRecords("45TCRB");
        if (!passRecordList.isEmpty()) {
            for (PassRecord passRecord : passRecordList) {
                if (TimeComparison(sdf.format(passRecord.getCreateTime()), 15)) {
                    AttributeValueRequestDTO valueRequestDTO = new AttributeValueRequestDTO();
                    valueRequestDTO.setAssetCode("46TCRB");
                    valueRequestDTO.setAttributeCode(CAR_DATA);
                    valueRequestDTO.setValue(passRecord.getCar_data());
                    reqClient.patchAttributeValue(valueRequestDTO);
                    Thread.sleep(1000);
                    valueRequestDTO.setValue(PLACE_HOLDING);
                    reqClient.patchAttributeValue(valueRequestDTO);
                    passRecordMapper.updateSite("46TCRB", passRecord.getId(), new Date());
                }
            }
        }
        passRecordList = passRecordMapper.selectPassRecords("46TCRB");
        if (!passRecordList.isEmpty()) {
            for (PassRecord passRecord : passRecordList) {
                if (TimeComparison(sdf.format(passRecord.getCreateTime()), 12)) {
                    AttributeValueRequestDTO valueRequestDTO = new AttributeValueRequestDTO();
                    valueRequestDTO.setAttributeCode(CAR_DATA);
                    valueRequestDTO.setValue(passRecord.getCar_data());
                    valueRequestDTO.setAssetCode("26TCRB");
                    reqClient.patchAttributeValue(valueRequestDTO);
                    Thread.sleep(1000);
                    valueRequestDTO.setValue(PLACE_HOLDING);
                    reqClient.patchAttributeValue(valueRequestDTO);
                    passRecordMapper.updateSite(valueRequestDTO.getAssetCode(), passRecord.getId(), new Date());
                }
            }
        }
        //22TCRB段
        passRecordList = passRecordMapper.selectPassRecordsTwoColorInput("22TCRB");
        if (!passRecordList.isEmpty()) {
            for (PassRecord passRecord : passRecordList) {
                if (TimeComparison(sdf.format(passRecord.getCreateTime()), 5)) {
                    AttributeValueRequestDTO valueRequestDTO = new AttributeValueRequestDTO();
                    valueRequestDTO.setAssetCode("1424RB");
                    valueRequestDTO.setAttributeCode(CAR_DATA);
                    valueRequestDTO.setValue(passRecord.getCar_data());
                    reqClient.patchAttributeValue(valueRequestDTO);
                    Thread.sleep(1000);
                    valueRequestDTO.setValue(PLACE_HOLDING);
                    reqClient.patchAttributeValue(valueRequestDTO);
                    passRecordMapper.updateSite("1424RB", passRecord.getId(), new Date());
                }
            }
        }
        passRecordList = passRecordMapper.selectPassRecords("1424RB");
        if (!passRecordList.isEmpty()) {
            for (PassRecord passRecord : passRecordList) {
                if (TimeComparison(sdf.format(passRecord.getCreateTime()), 8)) {
                    AttributeValueRequestDTO valueRequestDTO = new AttributeValueRequestDTO();
                    valueRequestDTO.setAssetCode("21TCRB");
                    valueRequestDTO.setAttributeCode(CAR_DATA);
                    valueRequestDTO.setValue(passRecord.getCar_data());
                    reqClient.patchAttributeValue(valueRequestDTO);
                    Thread.sleep(1000);
                    valueRequestDTO.setValue(PLACE_HOLDING);
                    reqClient.patchAttributeValue(valueRequestDTO);
                    passRecordMapper.updateSite("21TCRB", passRecord.getId(), new Date());
                }
            }
        }
        passRecordList = passRecordMapper.selectPassRecords("21TCRB");
        if (!passRecordList.isEmpty()) {
            for (PassRecord passRecord : passRecordList) {
                if (TimeComparisonOneMinute(sdf.format(passRecord.getCreateTime()))) {
                    AttributeValueRequestDTO valueRequestDTO = new AttributeValueRequestDTO();
                    valueRequestDTO.setAttributeCode(CAR_DATA);
                    valueRequestDTO.setValue(changeDestinationFlag(passRecord.getCar_data(), '1'));
                    valueRequestDTO.setAssetCode("22TCRB_1");
                    reqClient.patchAttributeValue(valueRequestDTO);
                    Thread.sleep(1000);
                    valueRequestDTO.setValue(PLACE_HOLDING);
                    reqClient.patchAttributeValue(valueRequestDTO);
                    valueRequestDTO.setAssetCode("22TCRB");
                    reqClient.patchAttributeValue(valueRequestDTO);
                    Thread.sleep(1000);
                    valueRequestDTO.setValue(PLACE_HOLDING);
                    reqClient.patchAttributeValue(valueRequestDTO);
                    passRecordMapper.updateSite24("22TCRB", passRecord.getId(), new Date(), "output");
                }
            }
        }

        passRecordList = passRecordMapper.selectPassRecordOutput("22TCRB");
        if (!passRecordList.isEmpty()) {
            for (PassRecord passRecord : passRecordList) {
                if (TimeComparisonOneMinute(sdf.format(passRecord.getCreateTime()))) {
                    AttributeValueRequestDTO valueRequestDTO = new AttributeValueRequestDTO();
                    valueRequestDTO.setAttributeCode(CAR_DATA);
                    valueRequestDTO.setValue(passRecord.getCar_data());
                    valueRequestDTO.setAssetCode("24LTRB");
                    reqClient.patchAttributeValue(valueRequestDTO);
                    Thread.sleep(1000);
                    valueRequestDTO.setValue(PLACE_HOLDING);
                    reqClient.patchAttributeValue(valueRequestDTO);
                    passRecordMapper.updateSite(valueRequestDTO.getAssetCode(), passRecord.getId(), new Date());
                }
            }
        }
        log.info("双色车执行结束" + "，时间：" + df.format(new Date()));
    }

    /**
     * 返修车辆出流程
     */
    @GetMapping("/repairOut")
    @Scheduled(cron = "0 */1 * * * ?")
    public void repairOut() throws InterruptedException {
        log.info("返修车回线执行开始，时间：{}", df.format(new Date()));
//        if (!scheduleTime()) {
////        if (!testFlag){
//            return;
//        }
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        //查询返修点数据
        List<PassRecord> passRecords = passRecordMapper.selectPassRecordsRepair();
        for (PassRecord passRecord : passRecords) {
            //随机30至90分钟，查询当前数据时差是否在此之上，若是则出-----后改为20分钟
            if (TimeComparison(sdf.format(passRecord.getCreateTime()), 20)) {
                AttributeValueRequestDTO attributeValueRequestDTO = new AttributeValueRequestDTO();
                attributeValueRequestDTO.setAttributeCode(CAR_DATA);
//                passRecord.setCar_data(changeDestinationFlag(passRecord.getCar_data(), '1'));
                attributeValueRequestDTO.setValue(passRecord.getCar_data());
                if ("YHJ31_1".equals(passRecord.getSite())) {
                    attributeValueRequestDTO.setAssetCode("YHJ31_1");
                    reqClient.patchAttributeValue(attributeValueRequestDTO);
                    Thread.sleep(1000);
                    attributeValueRequestDTO.setValue(PLACE_HOLDING);
                    reqClient.patchAttributeValue(attributeValueRequestDTO);

                    passRecord.setCar_data(changeDestinationFlag(passRecord.getCar_data(), '1'));
                } else if ("YHJ31_2".equals(passRecord.getSite())) {
                    attributeValueRequestDTO.setAssetCode("YHJ31_2");
                    reqClient.patchAttributeValue(attributeValueRequestDTO);
                    Thread.sleep(1000);
                    attributeValueRequestDTO.setValue(PLACE_HOLDING);
                    reqClient.patchAttributeValue(attributeValueRequestDTO);

                    passRecord.setCar_data(changeDestinationFlag(passRecord.getCar_data(), '2'));
                } else if ("YHJ31_3".equals(passRecord.getSite())) {
                    attributeValueRequestDTO.setAssetCode("YHJ31_3");
                    reqClient.patchAttributeValue(attributeValueRequestDTO);
                    Thread.sleep(1000);
                    attributeValueRequestDTO.setValue(PLACE_HOLDING);
                    reqClient.patchAttributeValue(attributeValueRequestDTO);

                    passRecord.setCar_data(changeDestinationFlag(passRecord.getCar_data(), '3'));
                } else if ("YHJ31_4".equals(passRecord.getSite())) {
                    attributeValueRequestDTO.setAssetCode("YHJ31_4");
                    reqClient.patchAttributeValue(attributeValueRequestDTO);
                    Thread.sleep(1000);
                    attributeValueRequestDTO.setValue(PLACE_HOLDING);
                    reqClient.patchAttributeValue(attributeValueRequestDTO);

                    passRecord.setCar_data(changeDestinationFlag(passRecord.getCar_data(), '4'));
                } else if ("YHJ31_5".equals(passRecord.getSite())) {
                    attributeValueRequestDTO.setAssetCode("YHJ31_5");
                    reqClient.patchAttributeValue(attributeValueRequestDTO);
                    Thread.sleep(1000);
                    attributeValueRequestDTO.setValue(PLACE_HOLDING);
                    reqClient.patchAttributeValue(attributeValueRequestDTO);

                    passRecord.setCar_data(changeDestinationFlag(passRecord.getCar_data(), '5'));
                } else if ("YHJ31_6".equals(passRecord.getSite())) {
                    attributeValueRequestDTO.setAssetCode("YHJ31_6");
                    reqClient.patchAttributeValue(attributeValueRequestDTO);
                    Thread.sleep(1000);
                    attributeValueRequestDTO.setValue(PLACE_HOLDING);
                    reqClient.patchAttributeValue(attributeValueRequestDTO);

                    passRecord.setCar_data(changeDestinationFlag(passRecord.getCar_data(), '6'));
                } else if ("YHJ31_7".equals(passRecord.getSite())) {
                    attributeValueRequestDTO.setAssetCode("YHJ31_7");
                    reqClient.patchAttributeValue(attributeValueRequestDTO);
                    Thread.sleep(1000);
                    attributeValueRequestDTO.setValue(PLACE_HOLDING);
                    reqClient.patchAttributeValue(attributeValueRequestDTO);

                    passRecord.setCar_data(changeDestinationFlag(passRecord.getCar_data(), '7'));
                } else if ("YHJ31_8".equals(passRecord.getSite()) || "YHJ31_8-repairOut".equals(passRecord.getSite())) {
                    attributeValueRequestDTO.setAssetCode("YHJ31_8");
                    reqClient.patchAttributeValue(attributeValueRequestDTO);
                    Thread.sleep(1000);
                    attributeValueRequestDTO.setValue(PLACE_HOLDING);
                    reqClient.patchAttributeValue(attributeValueRequestDTO);

                    passRecord.setCar_data(changeDestinationFlag(passRecord.getCar_data(), '8'));
                }
                if (passRecord.getSite().endsWith("-repairOut")) {
                    passRecord.setSite("YHJ31-repairOut");
                } else {
                    passRecord.setSite("YHJ31");
                }
                attributeValueRequestDTO.setAssetCode("YHJ31");
//                passRecord.setCar_data(changeDestinationFlag(passRecord.getCar_data(), '1'));
                attributeValueRequestDTO.setValue(passRecord.getCar_data());
                reqClient.patchAttributeValue(attributeValueRequestDTO);
                Thread.sleep(1000);
                attributeValueRequestDTO.setValue(PLACE_HOLDING);
                reqClient.patchAttributeValue(attributeValueRequestDTO);
                passRecordMapper.updateSite24(passRecord.getSite(), passRecord.getId(), new Date(), "output");
            }
        }
        //一分钟睡眠，查询24TCRB点位数据
        Thread.sleep(60000);
        //小返修
        List<PassRecord> passRecordList = passRecordMapper.selectPassRecordOutput("YHJ31");
//        int choose = passRecordMapper.selectChoose();
        for (PassRecord passRecord : passRecordList) {
            //若当前两个pass点不为放行标志，根据choose值将数据写入1398RB或1404RB
            AttributeValueRequestDTO valueRequestDTO = new AttributeValueRequestDTO();
            valueRequestDTO.setAttributeCode(CAR_DATA);
            valueRequestDTO.setValue(passRecord.getCar_data());

            // 给出口RB882写值
            valueRequestDTO.setAssetCode("RB882");
            reqClient.patchAttributeValue(valueRequestDTO);
            Thread.sleep(1000);
            valueRequestDTO.setValue(PLACE_HOLDING);
            reqClient.patchAttributeValue(valueRequestDTO);
            passRecordMapper.updateSite("RB882", passRecord.getId(), new Date());

            Thread.sleep(1000);

            Random randomNew = new Random();
            int chooseInt = randomNew.nextInt(2);

            List<PassRecord> rb882 = passRecordMapper.selectPassRecords("RB882");
            for (PassRecord passRecord1 : rb882){
                AttributeValueRequestDTO valueRequestDTO1 = new AttributeValueRequestDTO();
                valueRequestDTO1.setAttributeCode(CAR_DATA);
                valueRequestDTO1.setValue(passRecord1.getCar_data());

                if (chooseInt == 0) {
                    valueRequestDTO1.setAssetCode("SJT40");
                    reqClient.patchAttributeValue(valueRequestDTO1);
                    Thread.sleep(1000);
                    valueRequestDTO1.setValue(PLACE_HOLDING);
                    reqClient.patchAttributeValue(valueRequestDTO1);

                    passRecordMapper.updateSite("SJT40", passRecord1.getId(), new Date());
                } else {
                    valueRequestDTO1.setAssetCode("SJT41");
                    reqClient.patchAttributeValue(valueRequestDTO1);
                    Thread.sleep(1000);
                    valueRequestDTO1.setValue(PLACE_HOLDING);
                    reqClient.patchAttributeValue(valueRequestDTO1);

                    passRecordMapper.updateSite("SJT41", passRecord1.getId(), new Date());
                }
            }
        }
        //大返修
        passRecordList = passRecordMapper.selectPassRecordOutput("YHJ31-repairOut");
        for (PassRecord passRecord : passRecordList) {
            AttributeValueRequestDTO valueRequestDTO = new AttributeValueRequestDTO();
            valueRequestDTO.setAttributeCode(CAR_DATA);
            valueRequestDTO.setValue(passRecord.getCar_data());

            valueRequestDTO.setAssetCode("DF001");
            reqClient.patchAttributeValue(valueRequestDTO);
            Thread.sleep(1000);
            valueRequestDTO.setValue(PLACE_HOLDING);
            reqClient.patchAttributeValue(valueRequestDTO);

            Thread.sleep(1000);

            List<PassRecord> df001 = passRecordMapper.selectPassRecords("DF001");

            for (PassRecord passRecord1 : df001){
                AttributeValueRequestDTO valueRequestDTO1 = new AttributeValueRequestDTO();
                valueRequestDTO1.setAttributeCode(CAR_DATA);
                valueRequestDTO1.setValue(passRecord1.getCar_data());

                valueRequestDTO1.setAssetCode("SJ8");
                reqClient.patchAttributeValue(valueRequestDTO1);
                Thread.sleep(1000);
                valueRequestDTO1.setValue(PLACE_HOLDING);
                reqClient.patchAttributeValue(valueRequestDTO1);

                passRecordMapper.updateSite("SJ8", passRecord1.getId(), new Date());
            }
        }
        log.info("返修车回线执行结束，时间：{}", df.format(new Date()));
    }


    /**
     * 存储区（间休执行）
     */
//    @Scheduled(cron = "30 0/1 * * * ? ")
    @GetMapping("/saveSite")
    public void saveSite() throws InterruptedException {
        log.info("存储区（间休执行）执行开始，时间：{}", df.format(new Date()));
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        List<PassRecord> passRecordList = passRecordMapper.selectPassRecords("04TCRB-save");
        AttributeValueRequestDTO attributeValueRequestDTO = new AttributeValueRequestDTO();
        attributeValueRequestDTO.setAttributeCode("car_data");
        if (!passRecordList.isEmpty()) {
            for (PassRecord passRecord : passRecordList) {
                if (TimeComparisonOneMinute(sdf.format(passRecord.getCreateTime()))) {
                    attributeValueRequestDTO.setAssetCode("05TCRB");
                    attributeValueRequestDTO.setValue(passRecord.getCar_data());
                    reqClient.patchAttributeValue(attributeValueRequestDTO);
                    Thread.sleep(1000);
                    attributeValueRequestDTO.setValue(PLACE_HOLDING);
                    reqClient.patchAttributeValue(attributeValueRequestDTO);
                    passRecordMapper.updateSite("05TCRB", passRecord.getId(), new Date());
                }
            }
        }
        passRecordList = passRecordMapper.selectPassRecords("05TCRB");
        if (!passRecordList.isEmpty()) {
            for (PassRecord passRecord : passRecordList) {
                if (TimeComparisonOneMinute(sdf.format(passRecord.getCreateTime()))) {
                    attributeValueRequestDTO.setAssetCode("06TCRB");
                    attributeValueRequestDTO.setValue(passRecord.getCar_data());
                    reqClient.patchAttributeValue(attributeValueRequestDTO);
                    Thread.sleep(1000);
                    attributeValueRequestDTO.setValue(PLACE_HOLDING);
                    reqClient.patchAttributeValue(attributeValueRequestDTO);
                    passRecordMapper.updateSite("06TCRB", passRecord.getId(), new Date());
                }
            }
        }
        passRecordList = passRecordMapper.selectPassRecords("06TCRB");
        if (!passRecordList.isEmpty()) {
            for (PassRecord passRecord : passRecordList) {
                if (TimeComparisonOneMinute(sdf.format(passRecord.getCreateTime()))) {
                    attributeValueRequestDTO.setAssetCode("07TCRB");
                    attributeValueRequestDTO.setValue(passRecord.getCar_data());
                    reqClient.patchAttributeValue(attributeValueRequestDTO);
                    Thread.sleep(1000);
                    attributeValueRequestDTO.setValue(PLACE_HOLDING);
                    reqClient.patchAttributeValue(attributeValueRequestDTO);
                    passRecordMapper.updateSite("07TCRB", passRecord.getId(), new Date());
                }
            }
        }
        passRecordList = passRecordMapper.selectPassRecords("07TCRB");
        if (!passRecordList.isEmpty()) {
            for (PassRecord passRecord : passRecordList) {
                if (TimeComparisonOneMinute(sdf.format(passRecord.getCreateTime()))) {
                    attributeValueRequestDTO.setAssetCode("08TCRB");
                    attributeValueRequestDTO.setValue(passRecord.getCar_data());
                    reqClient.patchAttributeValue(attributeValueRequestDTO);
                    Thread.sleep(1000);
                    attributeValueRequestDTO.setValue(PLACE_HOLDING);
                    reqClient.patchAttributeValue(attributeValueRequestDTO);
                    passRecordMapper.updateSite("08TCRB", passRecord.getId(), new Date());
                }
            }
        }
        passRecordList = passRecordMapper.selectPassRecords("08TCRB");
        if (!passRecordList.isEmpty()) {
            for (PassRecord passRecord : passRecordList) {
                if (TimeComparisonOneMinute(sdf.format(passRecord.getCreateTime()))) {
                    attributeValueRequestDTO.setAssetCode("09TCRB");
                    attributeValueRequestDTO.setValue(passRecord.getCar_data());
                    reqClient.patchAttributeValue(attributeValueRequestDTO);
                    Thread.sleep(1000);
                    attributeValueRequestDTO.setValue(PLACE_HOLDING);
                    reqClient.patchAttributeValue(attributeValueRequestDTO);
                    passRecordMapper.updateSite("09TCRB", passRecord.getId(), new Date());
                }
            }
        }
        passRecordList = passRecordMapper.selectPassRecords("03TTRB-save");
        if (!passRecordList.isEmpty()) {
            for (PassRecord passRecord : passRecordList) {
                if (TimeComparisonOneMinute(sdf.format(passRecord.getCreateTime()))) {
                    attributeValueRequestDTO.setAssetCode("MQCH01_IN");
                    attributeValueRequestDTO.setValue(passRecord.getCar_data());
                    reqClient.patchAttributeValue(attributeValueRequestDTO);
                    Thread.sleep(1000);
                    attributeValueRequestDTO.setValue(PLACE_HOLDING);
                    reqClient.patchAttributeValue(attributeValueRequestDTO);
                    passRecordMapper.updateSite("MQCH01_IN", passRecord.getId(), new Date());
                }
            }
        }
        passRecordList = passRecordMapper.selectPassRecords("04TTRB-save");
        if (!passRecordList.isEmpty()) {
            for (PassRecord passRecord : passRecordList) {
                if (TimeComparisonOneMinute(sdf.format(passRecord.getCreateTime()))) {
                    attributeValueRequestDTO.setAssetCode("MQCH02_IN");
                    attributeValueRequestDTO.setValue(passRecord.getCar_data());
                    reqClient.patchAttributeValue(attributeValueRequestDTO);
                    Thread.sleep(1000);
                    attributeValueRequestDTO.setValue(PLACE_HOLDING);
                    reqClient.patchAttributeValue(attributeValueRequestDTO);
                    passRecordMapper.updateSite("MQCH02_IN", passRecord.getId(), new Date());
                }
            }
        }
        passRecordList = passRecordMapper.selectPassRecords("16TCRB-save");
        if (!passRecordList.isEmpty()) {
            for (PassRecord passRecord : passRecordList) {
                if (TimeComparison(sdf.format(passRecord.getCreateTime()), 1)) {
                    attributeValueRequestDTO.setAssetCode("16TCRB");
                    attributeValueRequestDTO.setValue(changeDestinationFlag(passRecord.getCar_data(), '0'));
                    reqClient.patchAttributeValue(attributeValueRequestDTO);
                    AttributeValueRequestDTO attributeValueRequestDTO1=new AttributeValueRequestDTO();
                    attributeValueRequestDTO1.setAssetCode("16TCRB_0");
                    attributeValueRequestDTO1.setAttributeCode(CAR_DATA);
                    attributeValueRequestDTO1.setValue(attributeValueRequestDTO.getValue());
                    reqClient.patchAttributeValue(attributeValueRequestDTO1);
                    Thread.sleep(1000);
                    attributeValueRequestDTO.setValue(PLACE_HOLDING);
                    reqClient.patchAttributeValue(attributeValueRequestDTO);
                    attributeValueRequestDTO1.setValue(PLACE_HOLDING);
                    reqClient.patchAttributeValue(attributeValueRequestDTO1);
                    passRecordMapper.updateSite("16TCRB-save-1", passRecord.getId(), new Date());
                }
            }
        }
        log.info("存储区（间休执行）执行结束，时间：{}", df.format(new Date()));
    }

    /**
     * 存储区（车辆释放）
     */
//    @Scheduled(cron = "30 0/1 * * * ? ")
    @GetMapping("/outSite")
    public void outSite() throws InterruptedException {
        log.info("存储区（车辆释放）执行开始，时间：{}", df.format(new Date()));
        if (!scheduleTime()) {
//        if (!testFlag){
            return;
        }
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        AttributeValueRequestDTO attributeValueRequestDTO = new AttributeValueRequestDTO();
        attributeValueRequestDTO.setAttributeCode("car_data");
        List<PassRecord> passRecordList = passRecordMapper.selectPassRecords("09TCRB");
        if (!passRecordList.isEmpty()) {
            for (PassRecord passRecord : passRecordList) {
                if (TimeComparisonOneMinute(sdf.format(passRecord.getCreateTime()))) {
                    attributeValueRequestDTO.setAssetCode("1085RB");
                    attributeValueRequestDTO.setValue(passRecord.getCar_data());
                    reqClient.patchAttributeValue(attributeValueRequestDTO);
                    Thread.sleep(1000);
                    attributeValueRequestDTO.setValue(PLACE_HOLDING);
                    reqClient.patchAttributeValue(attributeValueRequestDTO);
                    passRecordMapper.updateSite("1085RB", passRecord.getId(), new Date());
                }
            }
        }
        passRecordList = passRecordMapper.selectPassRecords("16TCRB-save-1");
        if (!passRecordList.isEmpty()) {
            for (PassRecord passRecord : passRecordList) {
                if (TimeComparison(sdf.format(passRecord.getCreateTime()), 1)) {
                    attributeValueRequestDTO.setAssetCode("17TCRB");
                    attributeValueRequestDTO.setValue(passRecord.getCar_data());
                    reqClient.patchAttributeValue(attributeValueRequestDTO);
                    Thread.sleep(1000);
                    attributeValueRequestDTO.setValue(PLACE_HOLDING);
                    reqClient.patchAttributeValue(attributeValueRequestDTO);
                    passRecordMapper.updateSite("17TCRB", passRecord.getId(), new Date());
                }
            }
        }
        passRecordList = passRecordMapper.selectPassRecords("17TCRB");
        if (!passRecordList.isEmpty()) {
            for (PassRecord passRecord : passRecordList) {
                if (TimeComparisonOneMinute(sdf.format(passRecord.getCreateTime()))) {
                    attributeValueRequestDTO.setAssetCode("41TCRB");
                    attributeValueRequestDTO.setValue(passRecord.getCar_data());
                    reqClient.patchAttributeValue(attributeValueRequestDTO);
                    Thread.sleep(1000);
                    attributeValueRequestDTO.setValue(PLACE_HOLDING);
                    reqClient.patchAttributeValue(attributeValueRequestDTO);
                    passRecordMapper.updateSite("41TCRB", passRecord.getId(), new Date());
                }
            }
        }
        passRecordList = passRecordMapper.selectPassRecords("41TCRB");
        if (!passRecordList.isEmpty()) {
            for (PassRecord passRecord : passRecordList) {
                if (TimeComparisonOneMinute(sdf.format(passRecord.getCreateTime()))) {
                    attributeValueRequestDTO.setAssetCode("42TCRB");
                    attributeValueRequestDTO.setValue(passRecord.getCar_data());
                    reqClient.patchAttributeValue(attributeValueRequestDTO);
                    Thread.sleep(1000);
                    attributeValueRequestDTO.setValue(PLACE_HOLDING);
                    reqClient.patchAttributeValue(attributeValueRequestDTO);
                    passRecordMapper.updateSite("42TCRB", passRecord.getId(), new Date());
                }
            }
        }
        passRecordList = passRecordMapper.selectPassRecords("42TCRB");
        if (!passRecordList.isEmpty()) {
            for (PassRecord passRecord : passRecordList) {
                if (TimeComparisonOneMinute(sdf.format(passRecord.getCreateTime()))) {
                    attributeValueRequestDTO.setAssetCode("16TCRB");
                    attributeValueRequestDTO.setValue(changeDestinationFlag(passRecord.getCar_data(), '2'));
                    reqClient.patchAttributeValue(attributeValueRequestDTO);
                    AttributeValueRequestDTO attributeValueRequestDTO1=new AttributeValueRequestDTO();
                    attributeValueRequestDTO1.setAssetCode("16TCRB_2");
                    attributeValueRequestDTO1.setAttributeCode(CAR_DATA);
                    attributeValueRequestDTO1.setValue(attributeValueRequestDTO.getValue());
                    reqClient.patchAttributeValue(attributeValueRequestDTO1);
                    Thread.sleep(1000);
                    attributeValueRequestDTO.setValue(PLACE_HOLDING);
                    reqClient.patchAttributeValue(attributeValueRequestDTO);
                    attributeValueRequestDTO1.setValue(PLACE_HOLDING);
                    reqClient.patchAttributeValue(attributeValueRequestDTO1);
                    passRecordMapper.updateSite("16TCRB", passRecord.getId(), new Date());
                }
            }
        }
        passRecordList = passRecordMapper.selectPassRecords("MQCH01_IN");
        if (!passRecordList.isEmpty()) {
            for (PassRecord passRecord : passRecordList) {
                if (TimeComparison(sdf.format(passRecord.getCreateTime()), 1)) {
                    attributeValueRequestDTO.setAssetCode("MQCH01_OUT");
                    reqClient.patchAttributeValue(attributeValueRequestDTO);
                    Thread.sleep(1000);
                    attributeValueRequestDTO.setValue(PLACE_HOLDING);
                    reqClient.patchAttributeValue(attributeValueRequestDTO);
                    passRecordMapper.updateSite("MQCH01_OUT", passRecord.getId(), new Date());
                }
            }
        }
        passRecordList = passRecordMapper.selectPassRecords("MQCH01_OUT");
        if (!passRecordList.isEmpty()) {
            for (PassRecord passRecord : passRecordList) {
                if (TimeComparisonOneMinute(sdf.format(passRecord.getCreateTime()))) {
                    attributeValueRequestDTO.setAssetCode("31TCRB");
                    reqClient.patchAttributeValue(attributeValueRequestDTO);
                    Thread.sleep(1000);
                    attributeValueRequestDTO.setValue(PLACE_HOLDING);
                    reqClient.patchAttributeValue(attributeValueRequestDTO);
                    passRecordMapper.updateSite("31TCRB", passRecord.getId(), new Date());
                }
            }
        }
        passRecordList = passRecordMapper.selectPassRecords("MQCH02_IN");
        if (!passRecordList.isEmpty()) {
            for (PassRecord passRecord : passRecordList) {
                if (TimeComparison(sdf.format(passRecord.getCreateTime()), 1)) {
                    attributeValueRequestDTO.setAssetCode("MQCH02_OUT");
                    reqClient.patchAttributeValue(attributeValueRequestDTO);
                    Thread.sleep(1000);
                    attributeValueRequestDTO.setValue(PLACE_HOLDING);
                    reqClient.patchAttributeValue(attributeValueRequestDTO);
                    passRecordMapper.updateSite("MQCH02_OUT", passRecord.getId(), new Date());
                }
            }
        }
        passRecordList = passRecordMapper.selectPassRecords("MQCH02_OUT");
        if (!passRecordList.isEmpty()) {
            for (PassRecord passRecord : passRecordList) {
                if (TimeComparisonOneMinute(sdf.format(passRecord.getCreateTime()))) {
                    attributeValueRequestDTO.setAssetCode("32TCRB");
                    reqClient.patchAttributeValue(attributeValueRequestDTO);
                    Thread.sleep(1000);
                    attributeValueRequestDTO.setValue(PLACE_HOLDING);
                    reqClient.patchAttributeValue(attributeValueRequestDTO);
                    passRecordMapper.updateSite("32TCRB", passRecord.getId(), new Date());
                }
            }
        }
        log.info("存储区（车辆释放）执行结束，时间：{}", df.format(new Date()));
    }

    /**
     * 车辆离线任务集合
     */
    private static final Map<String, String> siteMap = new HashMap<>();

    static {
        siteMap.put("1", "12TCRB");
        siteMap.put("2", "04STRB");
        siteMap.put("3", "05STRB");
        siteMap.put("4", "21LTRB");
        siteMap.put("5", "21TCRB");
        siteMap.put("6", "2147RB");
    }

    /**
     * 离线车辆定时任务
     */
//    @Scheduled(cron = "0/10 * * * * ?")
    @GetMapping("/offLine")
    public void offLine() {
        log.info("离线车辆任务执行开始，时间：{}", df.format(new Date()));
        String input = attributeValue.readNumOffline();
        if (input.length() >= 144) {
            // 计算字符串长度
            int length = input.length();
            // 循环遍历，每次取出17个字符
            for (int i = 0; i < length; i += 18) {
                // 如果剩余字符不足17个，则只取剩余部分
                int end = Math.min(i + 18, length);
                // 取子字符串
                String subStr = input.substring(i, end);
                //不包含---继续
                if (!subStr.contains("---")) {
                    PassRecord passRecord = passRecordMapper.selectPassRecordByVin(subStr.substring(0, 17));
                    if (passRecord != null) {
                        char lastChar = subStr.substring(17).charAt(subStr.substring(17).length() - 1);
                        //修改离线点标识
                        passRecordMapper.updateCarData(changeDestinationOffline(passRecord.getCar_data(), lastChar), passRecord.getId(), lastChar);
                    }
                }
            }
            //查找离线点标识车辆
            List<PassRecord> offLine = passRecordMapper.selectPassRecordOffline();
            //若离线点标识一致且当前站点一致则离线
            for (PassRecord offline : offLine) {
                for (Map.Entry<String, String> entry : siteMap.entrySet()) {
                    if (entry.getKey().contains(offline.getOffline()) && entry.getValue().equals(offline.getSite())) {
                        passRecordMapper.updateSite(offline.getSite() + "_offline", offline.getId(), new Date());
                    }
                }
            }
        }
        log.info("离线车辆任务执行结束，时间：{}", df.format(new Date()));
    }


    /**
     * VIN随机生成
     */
    public static String generateVin() {
        long date = LocalDateTime.now().toInstant(ZoneOffset.UTC).toEpochMilli();
        Random random = new Random();
        int randomNumber = random.nextInt(10) + 1;
        return ("vin" + date + randomNumber).substring(0, 17);
    }

    /**
     * 随机30到90分钟判断，大于为true
     */
    public static Boolean timeComparisonRandom(String specificTimeStr) {
        Random random = new Random();
        // 设置日期时间格式
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        // 解析字符串为LocalDateTime对象
        LocalDateTime specificTime = LocalDateTime.parse(specificTimeStr, formatter);
        // 获取当前时间
        LocalDateTime currentTime = LocalDateTime.now();
        // 创建一个表示5分钟的Duration
        Duration fiveMinutes = Duration.ofMinutes(random.nextInt(61) + 30);

        // 计算当前时间减去5分钟的时间点
        LocalDateTime fiveMinutesAgo = currentTime.minus(fiveMinutes);
        // 比较特定时间是否在5分钟之前
        return specificTime.isBefore(fiveMinutesAgo);
    }


    /**
     * 五分钟判断，大于五分钟为true
     */
    public static Boolean TimeComparisonFiveMinute(String specificTimeStr) {
        // 设置日期时间格式
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        // 解析字符串为LocalDateTime对象
        LocalDateTime specificTime = LocalDateTime.parse(specificTimeStr, formatter);
        // 获取当前时间
        LocalDateTime currentTime = LocalDateTime.now();
        // 创建一个表示5分钟的Duration
        Duration fiveMinutes = Duration.ofMinutes(5);
        // 计算当前时间减去5分钟的时间点
        LocalDateTime fiveMinutesAgo = currentTime.minus(fiveMinutes);
        // 比较特定时间是否在5分钟之前
        return specificTime.isBefore(fiveMinutesAgo);
    }

    /**
     * 一分钟判断，大于一分钟为true
     */
    public static Boolean TimeComparisonOneMinute(String specificTimeStr) {
        // 设置日期时间格式
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        // 解析字符串为LocalDateTime对象
        LocalDateTime specificTime = LocalDateTime.parse(specificTimeStr, formatter);
        // 获取当前时间
        LocalDateTime currentTime = LocalDateTime.now();
        // 创建一个表示1分钟的Duration
        Duration oneMinute = Duration.ofMinutes(1);
        // 判断特定时间是否在当前时间的前1分钟内（含1分钟前）
        boolean isWithinOneMinute = specificTime.isBefore(currentTime.minus(oneMinute));
        return isWithinOneMinute;
    }

    /**
     * 分钟判断，大于(输入)分钟为true
     */
    public static Boolean TimeComparison(String specificTimeStr, int minute) {
        // 设置日期时间格式
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        // 解析字符串为LocalDateTime对象
        LocalDateTime specificTime = LocalDateTime.parse(specificTimeStr, formatter);
        // 获取当前时间
        LocalDateTime currentTime = LocalDateTime.now();
        // 创建一个表示1分钟的Duration
        Duration oneMinute = Duration.ofMinutes(minute);
        // 判断特定时间是否在当前时间的前1分钟内（含1分钟前）
        boolean isWithinOneMinute = specificTime.isBefore(currentTime.minus(oneMinute));
        return isWithinOneMinute;
    }

    /**
     * 改变出入标志点
     * 目的路由
     * @param originalString
     * @param newChar
     * @return
     */
    public static String changeDestinationFlag(String originalString, char newChar) {
        // ====================================================
        // 长度变了，下标也要改
//        int indexToReplace = 73;
        int indexToReplace = 81;

        // 将字符串转换为char数组以进行修改
        char[] charArray = originalString.toCharArray();

        // 检查索引是否在数组范围内
        if (indexToReplace < charArray.length) {
            // 替换指定索引处的字符
            charArray[indexToReplace] = newChar;
        } else {
            log.info("索引超出字符串范围");
        }

        // 将修改后的char数组转换回字符串
        String modifiedString = new String(charArray);
        return modifiedString;
    }

    /**
     * 改变一次交检合格标识
     */
    public static String changeDestinationPass(String originalString, char newChar) {
        // ====================================================
        // 长度变了，下标也要改
        int indexToReplace = 71;

        // 将字符串转换为char数组以进行修改
        char[] charArray = originalString.toCharArray();

        // 检查索引是否在数组范围内
        if (indexToReplace < charArray.length) {
            // 替换指定索引处的字符
            charArray[indexToReplace] = newChar;
        } else {
            log.info("索引超出字符串范围");
        }

        // 将修改后的char数组转换回字符串
        String modifiedString = new String(charArray);
        return modifiedString;
    }


    /**
     * 改变直通标识
     */
    public static String changeDestinationDc(String originalString, char newChar) {
        // ====================================================
        // 长度变了，下标也要改
//        int indexToReplace = 72;
        int indexToReplace = 79;

        // 将字符串转换为char数组以进行修改
        char[] charArray = originalString.toCharArray();

        // 检查索引是否在数组范围内
        if (indexToReplace < charArray.length) {
            // 替换指定索引处的字符
            charArray[indexToReplace] = newChar;
        } else {
            log.info("索引超出字符串范围");
        }

        // 将修改后的char数组转换回字符串
        String modifiedString = new String(charArray);
        return modifiedString;
    }

    /**
     * 改变离线标识
     */
    public static String changeDestinationOffline(String originalString, char newChar) {
        // ====================================================
        // 长度变了，下标也要改
//        int indexToReplace = 74;
        int indexToReplace = 81;

        // 将字符串转换为char数组以进行修改
        char[] charArray = originalString.toCharArray();

        // 检查索引是否在数组范围内
        if (indexToReplace < charArray.length) {
            // 替换指定索引处的字符
            charArray[indexToReplace] = newChar;
        } else {
            log.info("索引超出字符串范围");
        }

        // 将修改后的char数组转换回字符串
        String modifiedString = new String(charArray);
        return modifiedString;
    }


    // 创建一个 DateTimeFormatter 对象用于格式化时间
    DateTimeFormatter formatter = DateTimeFormatter.ofPattern("HH:mm");
    LocalTime startTime1 = LocalTime.parse("08:00", formatter);
    LocalTime startTime2 = LocalTime.parse("10:00", formatter);
    LocalTime startTime3 = LocalTime.parse("10:15", formatter);
    LocalTime startTime4 = LocalTime.parse("11:30", formatter);
    LocalTime startTime5 = LocalTime.parse("12:15", formatter);
    LocalTime startTime6 = LocalTime.parse("13:00", formatter);
    LocalTime startTime7 = LocalTime.parse("14:15", formatter);
    LocalTime startTime8 = LocalTime.parse("16:00", formatter);
    LocalTime startTime10 = LocalTime.parse("20:00", formatter);
    LocalTime startTime11 = LocalTime.parse("22:00", formatter);
    LocalTime startTime12 = LocalTime.parse("22:15", formatter);
    LocalTime startTime13 = LocalTime.parse("23:30", formatter);
    LocalTime startTime14 = LocalTime.parse("00:15", formatter);
    LocalTime startTime15 = LocalTime.parse("03:00", formatter);
    LocalTime startTime16 = LocalTime.parse("03:15", formatter);
    LocalTime startTime17 = LocalTime.parse("04:00", formatter);

    /**
     * 上班时间判断，上班时间为true，否则为false
     *
     * @return
     */
    public Boolean scheduleTime() {
        return isbetween(startTime1, startTime2) || isbetween(startTime3, startTime4) || isbetween(startTime5, startTime6)
                || isbetween(startTime7, startTime8) || isbetween(startTime10, startTime11)
                || isbetween(startTime12, startTime13) || isbetween(startTime14, startTime15) || isbetween(startTime16, startTime17);
    }


    /**
     * 判断当前时间介于输入两个时间之间
     */
    public Boolean isbetween(LocalTime startTime, LocalTime endTime) {
        // 获取当前时间
        LocalTime currentTime = LocalTime.now();
        // 创建一个 DateTimeFormatter 对象用于格式化时间
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("HH:mm");
        // 格式化当前时间为字符串
        String formattedTime = currentTime.format(formatter);
        LocalTime checkDate = LocalTime.parse(formattedTime, formatter);
        boolean isBetween = !checkDate.isBefore(startTime) && !checkDate.isAfter(endTime);
        return isBetween;
    }

}
